ActionScript URLLoader URLRequest

I've got some problem with EventListener for loader:URLLoader. How can I determine if a file is already uploaded to the server or not?

var myRequest:URLRequest = new URLRequest("script.php");
loader.load(myRequest);
loader.addEventListener(Event.COMPLETE, redirect);

private function redirect(event:Event):void
{
navigateToURL(new URLRequest("http://example.com/"), "_self");
}

How can I determine if a file is already uploaded to the server or not?

If you want to see if a file exists, then you can add a listener for an IOErrorEvent.IO_ERROR to the URLLoader alongside your listener for Event.COMPLETE .

var urlRequest:URLRequest = new URLRequest("http://bleh.com/file.php");
var urlLoader:URLLoader = new URLLoader(urlRequest);


urlLoader.addEventListener(Event.COMPLETE, complete);
urlLoader.addEventListener(IOErrorEvent.IO_ERROR, failure);


function complete(e:Event):void
{
    initialize(true);
}


function failure(e:IOErrorEvent):void
{
    initialize(false);
}


function initialize(fileExists:Boolean):void
{
    urlLoader.removeEventListener(Event.COMPLETE, complete);
    urlLoader.removeEventListener(IOErrorEvent.IO_ERROR, failure);

    trace(fileExists);
}
链接地址: http://www.djcxy.com/p/41170.html

上一篇: HTTP动词,WebAPI

下一篇: ActionScript URLLoader URLRequest