EasyManua.ls Logo

MACROMEDIA FLASH 8-LEARNING ACTIONSCRIPT 2.0 IN FLASH - Page 642

MACROMEDIA FLASH 8-LEARNING ACTIONSCRIPT 2.0 IN FLASH
830 pages
Print Icon
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
642 Working with External Data
Flash Player 8 introduced the onHTTPStatus event handler for the LoadVars class, XML class,
and MovieClipLoader class to allow users to access the status code from an HTTP request.
This allows developers to determine why a particular load operation may have failed instead of
only being able to determine that a load operation already has failed.
The following example shows how you can use the LoadVars classs
onHTTPStatus event
handler to check whether a text file successfully downloaded from the server and what the
status code returned from the HTTP request was.
To check HTTP status with the LoadVars object:
1. Create a new Flash document and save it as loadvars.fla.
2. Add the following ActionScript to Frame 1 of the main Timeline:
this.createTextField("params_txt", 10, 10, 10, 100, 21);
params_txt.autoSize = "left";
var my_lv:LoadVars = new LoadVars();
my_lv.onHTTPStatus = function(httpStatus:Number) {
trace("HTTP status is: " + httpStatus);
};
my_lv.onLoad = function(success:Boolean) {
if (success) {
trace("text file successfully loaded");
params_txt.text = my_lv.dayNames;
} else {
params_txt.text = "unable to load text file";
}
};
my_lv.load("http://www.helpexamples.com/flash/404.txt");
/* output:
Error opening URL "http://www.helpexamples.com/flash/404.txt"
HTTP status is: 404
*/

Table of Contents

Related product manuals