-1

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.

PurkkaKoodari
  • 6,703
  • 6
  • 37
  • 58

2 Answers2

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);
BadFeelingAboutThis
  • 14,445
  • 2
  • 33
  • 40
  • Are you kidding me?! :) As long as he **creates** the URLRequest, he **knows** the url.. – Andrey Popov Jun 05 '14 at 19:56
  • 1
    @AndreyPopov - What if they are loading 50 things? What about code encapsulation and re usability? Do you know the context of this code? – BadFeelingAboutThis Jun 05 '14 at 20:00
  • In your case, the easiest solution would be to use a simple object to map loader to url, and then just get the url by using `loaders[e.target];`. Overriding such a class, for me, is an absurd. – Andrey Popov Jun 06 '14 at 12:29
  • The question is about IOErrorEvent and how to get it to trace what's needed. This is built-in in AS3 and works properly when used for proper purpose - debugging. I don't see how we came to this point to talk about encapsulating such a thing :) Anyways, I haven't said your answer is wrong, of course, it will work as you've describe, I just don't get why is this needed and why you offer such a hacked overloading solutions to something so simple (I don't want to know how he's going to get this 'trace' message, with a text box, really?!) – Andrey Popov Jun 06 '14 at 18:44
  • @AndreyPopov Well, I just looked at this and the idea of storing the request URL at the loader seems just great for me. I am using only one error function for ~10 files, so I really want to get the URL. I'll do exactly this (although with slight modifications to fit my project better). – PurkkaKoodari Jun 09 '14 at 13:54
-1

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

Andrey Popov
  • 7,362
  • 4
  • 38
  • 58
  • How will it help me? I can not install anything on the machine I will be running my application on; I must use a projector. – PurkkaKoodari Jun 05 '14 at 13:22
  • You asked how to see the full error in **standalone**. I explained it to you. Now you want to see it in exe - that's different question. There are different approaches, but all require external software like: http://demonsterdebugger.com/downloads – Andrey Popov Jun 05 '14 at 13:26