2010-04-16 76 views
2

當我執行下面的第二個代碼時出現了錯誤的URL(在URL末尾添加了數字「1」),我得到下面的錯誤。我怎樣才能捕獲這個錯誤,萬一網址錯了,這樣我就可以給用戶一個錯誤信息?如何捕捉Flash中的HTTP 404

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

    } 

回答

1

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.

你運行的Flash Player調試?您是否試過閱讀從瀏覽器打開您的應用程序產生的跟蹤消息,而不僅僅是玩家?從上面的文字看來,它好像只會在某些情況下才會觸發。