独立运行时,为什么不IOErrorEvents包含的网址是什么?独立、网址、IOErrorEvents

由网友(回忆不能淡忘)分享简介:下面是一个 的URLLoader 。Here is a simple example of an URLLoader.var loader:URLLoader = new URLLoader();var request:URLRequest = new URLRequest("http://example.co...

下面是一个 的URLLoader 。

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

此行​​为古怪。

从Flash或调试从闪存中运行时,该错误看起来是这样的。

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

[IOErrorEvent TYPE =ioError在泡沫=假可取消=假的EventPhase = 2文本=错误#2032:流错误网址:的 http://example.com/doesntexist.txt ]

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

不过,由于运行时瑞士法郎的.exe 投影机,它看起来像这样。

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

[IOErrorEvent TYPE =ioError在泡沫=假可取消=假的EventPhase = 2文本=错误#2032]

[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?

编辑:我需要得到它的工作作为一个投影机

I need to get it working as a projector.

推荐答案

虽然我不能确定为什么(可能是背后的Flash Player中的场景效率的事情),这里是一个办法来完成你想什么

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:

您可以编写扩展的自定义类的URLLoader 的存储网址给你。

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);
阅读全文

相关推荐

最新文章