PDA

View Full Version : How to handle errors of external SWF files?


aconrad
12-11-2008, 11:44 AM
Hello,

I wrote a multimedia player in AIR and I'm trying to handle eventual errors coming from external SWF files. The external SWF file is locally present on disk.

So I created a loader to load the SWF (very classic):



var req:URLRequest = new URLRequest("animation.swf")
var loader:Loader = new Loader();
loader.addEventListener(Event.COMPLETE, this.onSwfLoaded);
loader.load(req);

function onSwfLoaded(event:Event) {
var movie:MovieClip = this.loader.content as MovieClip;
movie.addEventListener(Event.COMPLETE, this.onSwfComplete);
movie.play();
}

function onSwfComplete(event:Event) {
trace("The SWF file has dispatched a COMPLETE event, it has finished playing.");
}


But the loaded SWF actually tries to load an image that does not exist and I get a "Error #2044: Unhandled IOErrorEvent:. text=Error #2035: URL Not Found.".

So my idea here is to be able to handle this error message that is unhandled by the SWF so my application can skips it to be able to render the next media in the playlist.

I tried to add the following


movie.addEventListener(IOErrorEvent.IO_ERROR, this.onSwfBroken);


But it doesn't work. The error message gets though. Ideas ?

Thanks for the help.

Regards,
Alex

rawmantick
12-11-2008, 12:15 PM
Don't mix errors and events.

To catch an error you need to use try{} catch{} statement. To catch an event - event listener.

You can see what errors cab be thrown and what events can be dispatched from a method in documentation.

aconrad
12-11-2008, 01:25 PM
Hello romantique,

Don't mix errors and events.

To catch an error you need to use try{} catch{} statement. To catch an event - event listener.

You can see what errors cab be thrown and what events can be dispatched from a method in documentation.

The problem is that I don't know how to catch the error it self, I tried adding try/catch as the following:


var req:URLRequest = new URLRequest("animation.swf");
var loader:Loader = new Loader();
loader.addEventListener(Event.COMPLETE, this.onSwfLoaded);
loader.load(req);

function onSwfLoaded(event:Event) {
var movie:MovieClip = this.loader.content as MovieClip;
movie.addEventListener(Event.COMPLETE, this.onSwfComplete);
try {
movie.play();
}
catch (err:*) {
// do something useful.
}
}

function onSwfComplete(event:Event) {
trace("The SWF file has dispatched a COMPLETE event, it has finished playing.");
}


But it goes through. I'm unable to catch the error as play() is non-blocking. It passes silently. And after a few frames playing, the loaded SWF can fail for any reason, and I can't handle the error coming from the loaded SWF.

Ideas ?

Regards,
Alex

rawmantick
12-11-2008, 01:30 PM
The loadinf process goes wrong. So you should "try" exactly it.

try
{
loader.load();
}...

aconrad
12-11-2008, 04:50 PM
I did test try {loader.load(req)} but I get the same error.

The loading process goes OK. The function "onSwfLoaded" is called correctly.

My problem is that the SWF file (animation.swf) that I'm loading is it self trying to load an image on disk, which fails to find because that image does not exist. And "animation.swf" doesn't have a IO_ERROR handler which makes it crash, and which makes my player crash.

To make things clear, my player loads an animation, which atempts to load an image that doesn't exist. And I want to prevent my player to crash.

player.swf
> loads animation.swf
> loads image.gif (not found)
> the loader of animation.swf dispatches IO_ERROR + crash because no IO_ERROR handler
> player.swf crashes because it can not handle/prevent the crash.

IfOnlyIThoughtOfThat
09-15-2010, 05:50 PM
I did test try {loader.load(req)} but I get the same error.

The loading process goes OK. The function "onSwfLoaded" is called correctly.


Sorry to post on such an old thread but this describes the exact problem i am having too. I am loading an external SWF file the code of which i have no control over, that SWF loads fine but displays an unhandled error when trying to load a jpg that doesnt exist.

I have no ability to change the code of the external SWF i just want to handle any errors it does not in my SWF that loads it. Is this even possible?

A,