How to catch a HTTP 404 in Flash
Posted
by Quandary
on Stack Overflow
See other posts from Stack Overflow
or by Quandary
Published on 2010-04-16T14:32:21Z
Indexed on
2010/04/21
14:43 UTC
Read the original article
Hit count: 629
When I execute the (2nd) below code with a wrong url (number '1' added at the URL end), I get the below error. How can I catch this error, in case the url is wrong, so that I can give out an error message to the user ?
Error opening URL 'http://localhost/myapp/cgi-bin/savePlanScale.ashx1?NoCache%5FRaumplaner=F7CF6A1E%2D7700%2D8E33%2D4B18%2D004114DEB39F&ScaleString=5%2E3&ModifyFile=data%2Fdata%5Fzimmere03e1e83%2D94aa%2D488b%2D9323%2Dd4c2e8195571%2Exml' httpStatusHandler: [HTTPStatusEvent type="httpStatus" bubbles=false cancelable=false eventPhase=2 status=404] status: 404 Error: Error #2101: Der an URLVariables.decode() übergebene String muss ein URL-kodierter Abfrage-String mit Name/Wert-Paaren sein. at Error$/throwError() at flash.net::URLVariables/decode() at flash.net::URLVariables() at flash.net::URLLoader/onComplete()
public static function NotifyASPXofNewScale(nScale:Number)
{
var strURL:String ="http://localhost/myapp/cgi-bin/savePlanScale.ashx1"
// CAUTION: when called from website, RELATIVE url...
var scriptRequest:URLRequest = new URLRequest(strURL);
var scriptLoader:URLLoader = new URLLoader();
// loader.dataFormat = URLLoaderDataFormat.TEXT; // default, returns as string
scriptLoader.dataFormat = URLLoaderDataFormat.VARIABLES; // returns URL variables
// loader.dataFormat = URLLoaderDataFormat.BINARY; // to load in images, xml files, and swf instead of the normal methods
var scriptVars:URLVariables = new URLVariables();
scriptLoader.addEventListener(Event.COMPLETE, onLoadSuccessful);
scriptLoader.addEventListener(IOErrorEvent.IO_ERROR, onLoadError);
scriptLoader.addEventListener(HTTPStatusEvent.HTTP_STATUS, httpStatusHandler);
scriptLoader.addEventListener(SecurityErrorEvent.SECURITY_ERROR, onSecurityError);
scriptVars.NoCache_Raumplaner = cGUID.create();
scriptVars.ScaleString = nScale;
scriptVars.ModifyFile = "data/data_zimmere03e1e83-94aa-488b-9323-d4c2e8195571.xml";
scriptRequest.method = URLRequestMethod.GET;
scriptRequest.data = scriptVars;
scriptLoader.load(scriptRequest);
function httpStatusHandler(event:HTTPStatusEvent):void
{
trace("httpStatusHandler: " + event);
trace("status: " + event.status);
}
function onLoadSuccessful(evt:Event):void
{
trace("cSaveData.NotifyASPXofNewScale.onLoadSuccessful");
trace("Response: " + evt.target.data);
ExternalInterface.call("alert", "Die neue Skalierung wurde erfolgreich gespeichert.");
//getURL("javascript:alert(\""+"Die neue Skalierung wurde erfolgreich gespeichert.\\nALLE Instanzen des Browsers schliessen und neu starten, damit die Änderung in Kraft tritt."+"\");");
if (evt.target.data.responseStatus == "YOUR FAULT")
{
trace("Error: Flash transmitted an illegal scale value.");
ExternalInterface.call("alert", "Fehler: Flash konnte die neue Skalierung nicht abspeichern.");
}
if (evt.target.data.responseStatus == "EXCEPTION")
{
trace("Exception in ASP.NET: " + evt.target.data.strError);
ExternalInterface.call("alert", "Exception in ASP.NET: " + evt.target.data.strError);
}
}
function onLoadError(evt:IOErrorEvent):void
{
trace("cSaveData.NotifyASPXofNewScale.onLoadError");
trace("Error: ASPX or Transmission error. ASPX responseStatus: " + evt);
ExternalInterface.call("alert", "ASPX - oder Übertragungsfehler.\\nASPX responseStatus: " + evt);
//getURL("javascript:alert(\"" + "ASPX - oder Übertragungsfehler.\\nASPX responseStatus: " + receiveVars.responseStatus + "\");");
}
function onSecurityError(evt:SecurityErrorEvent):void
{
trace("cSaveData.NotifyASPXofNewScale.onSecurityError");
trace("Security error: " + evt);
ExternalInterface.call("alert", "Sicherheitsfehler. Beschreibung: " + evt);
}
}
© Stack Overflow or respective owner