About XML
659
The following example shows how you can use the XML class’s
onHTTPStatus
event handler
to check whether an XML file successfully downloaded from the server and what the status
code returned from the HTTP request was.
Checking HTTP status codes using the XML class:
1.
Create a new Flash document and save it as
xmlhttp.fla
.
2.
Add the following ActionScript to Frame 1 of the main Timeline:
var my_xml:XML = new XML();
my_xml.ignoreWhite = true;
my_xml.onHTTPStatus = function(httpStatus:Number) {
trace("HTTP status is: " + httpStatus);
};
my_xml.onLoad = function(success:Boolean) {
if (success) {
trace("XML successfully loaded");
// 0 (No error; parse was completed successfully.)
trace("XML status is: " + my_xml.status);
} else {
trace("unable to load XML");
}
};
my_xml.load("http://www.helpexamples.com/crossdomain.xml");
The previous code defines a new XML object with the variable name
my_xml
, defines two
event handlers (
onHTTPStatus
and
onLoad
), and loads an external XML file. The
onLoad
event handler checks to see whether the XML file was successfully loaded and if so sends a
message to the Output panel as well as traces the XML object’s status property. It is
important to remember that the
onHTTPStatus
event listener returns the status code
returned from the web server, whereas the
XML.status
property contains a numeric value
that indicates whether the XML object was able to be parsed successfully.
3.
Select Control > Test Movie to test the Flash document.
TI
P
The
XML.onHTTPStatus
event handler is new to Flash Player 8.
WARN
ING
Don’t confuse the HTTP httpStatus codes with the XML class’s
status
property. The
onHTTPStatus
event handler returns the server’s status code from an HTTP request
and the
status
property automatically sets and returns a numeric value that indicates
whether an XML document was successfully parsed into an XML object.
CAU
T
IO
N
If a web server does not return a
status
code to the Flash Player, the number 0 is
returned to the
onHTTPStatus
event handler.
Содержание FLASH 8-LEARNING ACTIONSCRIPT 2.0 IN FLASH
Страница 1: ...Learning ActionScript 2 0 in Flash...
Страница 8: ...8 Contents...
Страница 18: ...18 Introduction...
Страница 30: ...30 What s New in Flash 8 ActionScript...
Страница 66: ...66 Writing and Editing ActionScript 2 0...
Страница 328: ...328 Interfaces...
Страница 350: ...350 Handling Events...
Страница 590: ...590 Creating Interaction with ActionScript...
Страница 710: ...710 Understanding Security...
Страница 730: ...730 Debugging Applications...
Страница 780: ...780 Deprecated Flash 4 operators...
Страница 830: ...830 Index...