View comments | RSS feed

onHTTPStatus (XML.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. It's important to note that after onHTTPStatus is triggered, onData is always subsequently triggered, regardless of whether or not you override onHTTPStatus. To best use the onHTTPStatus handler, write an appropriate function to catch the result of the onHTTPStatus call; you can then use the result in your onData or onLoad handler functions. 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.

If Flash Player cannot get a status code from the server or if Flash Player 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, such as if a malformed URL is requested, and is always generated by the Flash Player plug-in when run in the following browsers, which do not pass HTTP status codes to the player: Netscape, Mozilla, Safari, Opera, or Internet Explorer for the Macintosh.

Availability: ActionScript 1.0; Flash Player 8

Parameters

httpStatus:Number - The HTTP status code returned by the server. For example, a value of 404 indicates that the server has not found anything matching 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.

Example

The following example shows how to use the onHTTPStatus method to help with debugging. The example collects HTTP status codes and assigns their value and type to an instance of the XML object (notice that this example creates the instance members this.httpStatus and this.httpStatusType at runtime). The onData method uses these to trace information about the HTTP response that could be useful when debugging.

var myXml:XML = new XML();

myXml.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";
    }
}

myXml.onData = function(src:String) {
    trace(">> " + this.httpStatusType + ": " + this.httpStatus);
    if(src != undefined) {
        this.parseXML(src);
        this.loaded = true;
        this.onLoad(true);
    }
    else {
        this.onLoad(false);
    }
}

myXml.onLoad = function(success:Boolean) {
}

myXml.load("http://weblogs.macromedia.com/mxna/xml/rss.cfm?query=byMostRecent&languages=1");

See also

onHTTPStatus (LoadVars.onHTTPStatus handler), load (XML.load method), sendAndLoad (XML.sendAndLoad method)


Version 8

Comments


d_wood said on Feb 23, 2006 at 9:51 AM :
Only a slight problem with this: it doesn't exist.

When I define:

var loader:XML = new XML();
loader.onHTTPStatus = function(httpStatus:Number)
{
mystatus.rememberHTTPCode(httpStatus);
}

According to Flash 8:

"...There is no property with the name 'onHTTPStatus'.
loader.onHTTPStatus = function(httpStatus:Number)

Total ActionScript Errors: 1 Reported Errors: 1"

And yes, that means the example code in this page doesn't actually work either.
d_wood said on Feb 27, 2006 at 4:13 PM :
I need to retract the previous comment on this page. I discovered why this happens; if you export in Flash 7 instead of 8, this failure is the result you get.
Andy Kirkham said on Jul 20, 2006 at 4:05 AM :
I suggest that the example code represents poor practice. XML is not a dynamic class and therefore it should not be possible to add instance members this.httpStatus and this.httpStatusType at runtime. I think this example only works because the XML instance is declared on the timeline where type checking is relaxed. An identical example is given in the documentation for LoadVars.onHTTPStatus(), but there it is legitimate because LoadVars *is* a dynamic class.

I wonder why the one class is dynamic and the other isn't.
denis_bohm said on Jul 2, 2007 at 12:47 PM :
With Firefox 2.0.0.4 on Mac Intel 10.4.10 the onHTTPStatus handler is not
called at all if a connection can not be established with the server.

So it appers there is no way to detect if a connection can't be established...

 

RSS feed | Send me an e-mail when comments are added to this page | Comment Report

Current page: http://livedocs.adobe.com/flash/8/main/00002875.html