开发者

How to catch a HTTP 404 in Flash

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);
   }

   }


From http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/net/URLLoader.html#event:httpStatus

httpStatus: Dispatched if a call to URLLoader.load() attempts to access data over HTTP. For content running in Flash Player, this event is only dispatched if the current Flash Player environment is able to detect and return the status code for the request. (Some browser environments may not be able to provide this information.) Note that the httpStatus event (if any) is sent before (and in addition to) any complete or error event.

Are you running the Flash Player Debugger? Have you tried reading the trace messages produced from opening your application from a browser, and not just the player? From the text above, it seems as though it will only fire under certain circumstances.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜