Categories
Flash

RTFM: onHTTPStatus

For some time I wanted to create better feedback (error or alert) when you use cross-domain data (XML, TXT, JPG, FLV, etc.).
The more experienced flash programmer know that this you need a crossdomain.xml.

But flash never gives you any feedback if you need the crossdomain.xml of is it’s there or not. So you need Fiddler , Charles or some other http debugger to debug.

In the helpfiles of Flash I found the documentation about onHTTPStatus and more information about HTTP specification and after a quick scan of the information there I decided this is what I needed.

I wrote a class that would give me feedback…….. and all I got back was a 0 (zero) in Firefox and 404 using IE. Thats a strange bug…. so I started to read the helpfiles a little beter and found this:

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.

So that killed the experiment immediately: I can’t have code that only work in IE.

But if YOU need http feedback and you’re using only IE I have some code for you:

function temp(httpStatusType:Number):String {
	var httpStatusTxt:String = "";
	switch (httpStatusType) {
	case 100 :
		httpStatusTxt = "Continue";
		break;
	case 101 :
		httpStatusTxt = "Switching Protocols";
		break;
	case 200 :
		httpStatusTxt = "OK";
		break;
	case 201 :
		httpStatusTxt = "Created";
		break;
	case 202 :
		httpStatusTxt = "Accepted";
		break;
	case 203 :
		httpStatusTxt = "Non-Authoritative Information";
		break;
	case 204 :
		httpStatusTxt = "No Content";
		break;
	case 205 :
		httpStatusTxt = "Reset Content";
		break;
	case 206 :
		httpStatusTxt = "Partial Content";
		break;
	case 300 :
		httpStatusTxt = "Multiple Choices";
		break;
	case 301 :
		httpStatusTxt = "Moved Permanently";
		break;
	case 302 :
		httpStatusTxt = "Found";
		break;
	case 303 :
		httpStatusTxt = "See Other";
		break;
	case 304 :
		httpStatusTxt = "Not Modified";
		break;
	case 305 :
		httpStatusTxt = "Use Proxy";
		break;
	case 307 :
		httpStatusTxt = "Temporary Redirect";
		break;
	case 400 :
		httpStatusTxt = "Bad Request";
		break;
	case 401 :
		httpStatusTxt = "Unauthorized";
		break;
	case 402 :
		httpStatusTxt = "Payment Required";
		break;
	case 403 :
		httpStatusTxt = "Forbidden";
		break;
	case 404 :
		httpStatusTxt = "Not Found";
		break;
	case 405 :
		httpStatusTxt = "Method Not Allowed";
		break;
	case 406 :
		httpStatusTxt = "Not Acceptable";
		break;
	case 407 :
		httpStatusTxt = "Proxy Authentication Required";
		break;
	case 408 :
		httpStatusTxt = "Request Time-out";
		break;
	case 409 :
		httpStatusTxt = "Conflict";
		break;
	case 410 :
		httpStatusTxt = "Gone";
		break;
	case 411 :
		httpStatusTxt = "Length Required";
		break;
	case 412 :
		httpStatusTxt = "Precondition Failed";
		break;
	case 413 :
		httpStatusTxt = "Request Entity Too Large";
		break;
	case 414 :
		httpStatusTxt = "Request-URI Too Large";
		break;
	case 415 :
		httpStatusTxt = "Unsupported Media Type";
		break;
	case 416 :
		httpStatusTxt = "Requested range not satisfiable";
		break;
	case 417 :
		httpStatusTxt = "Expectation Failed";
		break;
	case 500 :
		httpStatusTxt = "Internal Server Error";
		break;
	case 501 :
		httpStatusTxt = "Not Implemented";
		break;
	case 502 :
		httpStatusTxt = "Bad Gateway";
		break;
	case 503 :
		httpStatusTxt = "Service Unavailable";
		break;
	case 504 :
		httpStatusTxt = "Gateway Time-out";
		break;
	case 505 :
		httpStatusTxt = "HTTP Version not supported";
		break;
	default :
		httpStatusTxt = "Flash error";
		break;
	}
	return (httpStatusTxt);
}