2010-04-16 6 views
2

un HTTP 404 Quand je l'exercerai (2) ci-dessous le code avec un mauvais URL (numéro « 1 » ajouté à la fin de l'URL), je reçois l'erreur ci-dessous. Comment est-ce que je peux attraper cette erreur, au cas où l'URL est fausse, de sorte que je puisse donner un message d'erreur à l'utilisateur?Comment attraper Flash

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

    } 

Répondre

1

De 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.

Êtes-vous en cours d'exécution, Flash Player Debugger? Avez-vous essayé de lire les messages de trace produits en ouvrant votre application depuis un navigateur, et pas seulement le lecteur? D'après le texte ci-dessus, il semble que cela ne se déclenchera que dans certaines circonstances.

Questions connexes