jeudi 24 septembre 2015

AS3 IOErrorEvent.IO_ERROR event not catching if file doesn't exist

This doesn't make any sense. I'm trying to load a simple text file. If the file name is just "jeffaberle.txt" then it works fine because that file exists in the location specified. However if the name is changed to "jeffaberle2.txt" the code produces an error because this file does not exist on the server.

I want the IOErrorEvent to fire if the file is missing, but it doesn't fire. There's clearly something I'm missing. Any suggestions?

import flash.events.*;
import flash.net.URLRequest;
import flash.net.URLLoader;

var urlRequest:URLRequest = new URLRequest("http://ift.tt/1MLQYRT" + "?" + Math.random());  // + Math.random()
var urlLoader:URLLoader = new URLLoader();
urlLoader.dataFormat = URLLoaderDataFormat.VARIABLES;
urlLoader.addEventListener(Event.COMPLETE, completeHandler);
urlLoader.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);

urlLoader.load(urlRequest);

function completeHandler(e:Event):void {
    if (urlLoader.data.trialversion == "true") {
        trace("true");
    } else {
        trace("false");
    }
}
function ioErrorHandler(e:IOErrorEvent):void {
    trace("ioErrorHandlerJeff: " + e.toString());
}

Aucun commentaire:

Enregistrer un commentaire