Flash 8 Documentation |
|||
| ActionScript 2.0 Language Reference > ActionScript classes > LoadVars > onHTTPStatus (LoadVars.onHTTPStatus handler) | |||
onHTTPStatus = function(httpStatus:Number) {}
Invoked when Flash Player receives an HTTP status code from the server. This handler lets you capture and act on HTTP status codes.
The onHTTPStatus handler is invoked before onData, which triggers calls to onLoad with a value of undefined if the load fails. After onHTTPStatus is triggered, onData is always triggered, whether or not you override onHTTPStatus. To best use the onHTTPStatus handler, you should write a function to catch the result of the onHTTPStatus call; you can then use the result in your onData and onLoad handlers. If onHTTPStatus is not invoked, this indicates that the player did not try to make the URL request. This can happen because the request violates security sandbox rules for the SWF file.
If Flash Player cannot get a status code from the server, or if it cannot communicate with the server, the default value of 0 is passed to your ActionScript code. A value of 0 can be generated in any player (for example, if a malformed URL is requested), and a value of 0 is always generated by the Flash Player plug-in when it is run in the following browsers, which do not pass HTTP status codes to the player: Netscape, Mozilla, Safari, Opera, and Internet Explorer for the Macintosh.
Availability: ActionScript 1.0; Flash Player 8
httpStatus:Number - The HTTP status code returned by the server. For example, a value of 404 indicates that the server has not found a match for the requested URI. HTTP status codes can be found in sections 10.4 and 10.5 of the HTTP specification at ftp://ftp.isi.edu/in-notes/rfc2616.txt.
The following example shows how to use onHTTPStatus() to help with debugging. The example collects HTTP status codes and assigns their value and type to an instance of the LoadVars object. (Notice that this example creates the instance members this.httpStatus and this.httpStatusType at runtime.) The onData method uses these instance members to trace information about the HTTP response that can be useful in debugging.
var myLoadVars:LoadVars = new LoadVars();
myLoadVars.onHTTPStatus = function(httpStatus:Number) {
this.httpStatus = httpStatus;
if(httpStatus < 100) {
this.httpStatusType = "flashError";
}
else if(httpStatus < 200) {
this.httpStatusType = "informational";
}
else if(httpStatus < 300) {
this.httpStatusType = "successful";
}
else if(httpStatus < 400) {
this.httpStatusType = "redirection";
}
else if(httpStatus < 500) {
this.httpStatusType = "clientError";
}
else if(httpStatus < 600) {
this.httpStatusType = "serverError";
}
}
myLoadVars.onData = function(src:String) {
trace(">> " + this.httpStatusType + ": " + this.httpStatus);
if(src != undefined) {
this.decode(src);
this.loaded = true;
this.onLoad(true);
}
else {
this.onLoad(false);
}
}
myLoadVars.onLoad = function(success:Boolean) {
}
myLoadVars.load("http://weblogs.macromedia.com/mxna/flashservices/getMostRecentPosts.cfm");
onHTTPStatus (XML.onHTTPStatus handler), load (LoadVars.load method), sendAndLoad (LoadVars.sendAndLoad method)
Version 8
Send me an e-mail when comments are added to this page | Comment Report
Current page: http://livedocs.adobe.com/flash/8/main/00002333.html