Why don't IOErrorEvents contain the URL when running standalone?

旧巷老猫 提交于 2019-12-12 06:46:29

问题


Here is a simple example of an URLLoader.

var loader:URLLoader = new URLLoader();
var request:URLRequest = new URLRequest("http://example.com/doesntexist.txt");
loader.addEventListener(IOErrorEvent.IO_ERROR, function(e:IOErrorEvent){
    textbox.text = e.toString(); // Text box on stage
});
loader.load(request);

This behaves weirdly.

When running from Flash or debugging from Flash, the error looks like this.

[IOErrorEvent type="ioError" bubbles=false cancelable=false eventPhase=2 text="Error #2032: Stream Error. URL: http://example.com/doesntexist.txt"]

But, when running as a .swf or an .exe projector, it looks like this.

[IOErrorEvent type="ioError" bubbles=false cancelable=false eventPhase=2 text="Error #2032"]

Why is this so? Is there a way to get the first result when standalone?

EDIT: I need to get it working as a projector.


回答1:


While I'm not sure about the why (probably an efficiency thing behind the scenes in flash player), here is a way to accomplish what you'd like:

You can write a custom class that extends URLLoader that stores the url for you.

package 
{
    import flash.net.URLLoader;
    import flash.net.URLRequest;

    public class MyURLLoader extends URLLoader
    {
        public var request:URLRequest; //all were doing here is adding this public property and setting it when loading into the URLLoader

        public function MyURLLoader(request_:URLRequest) {
            request = request_;
            super(request);
        }

        override public function load(request_:URLRequest):void 
        {
            request = request_;
            super.load(request);
        }
    }
}

Then when handling your error, you can reference the URL like so:

var loader:MyURLLoader = new MyURLLoader();
var request:URLRequest = new URLRequest("http://example.com/doesntexist.txt");

loader.addEventListener(IOErrorEvent.IO_ERROR, function(e:IOErrorEvent){
    textbox.text = e.toString() + " URL: " + MyURLLoader(e.currentTarget).request; // Text box on stage
});
loader.load(request);



回答2:


Install Debugger Flash Player from: http://www.adobe.com/support/flashplayer/downloads.html This will help you.



来源:https://stackoverflow.com/questions/24060278/why-dont-ioerrorevents-contain-the-url-when-running-standalone

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!