Jump to content
Search Community

Catching uncaught error events when using SWFLoader

sprog test
Moderator Tag

Recommended Posts

I am currently working on a project where I need to load SWF movies created by third parties. Now some third parties have the problem that they sometimes throw runtime errors which is not great. Now I would like to listen to the new 10.1 event called

uncaughtErrorEvents

.

 

Only how can I listen to this evening when using the SWFLoader? I am currently using the following code:

 

_movieLoader = new SWFLoader( contentURL, new SWFLoaderVars()
     .autoPlay(false)
     .onComplete(onContentLoaded)
     .onError(onContentError)
     .integrateProgress(false)
     .width(1280)
     .height(768)
);

 

Based on this article http://labs.almerblank.com/2010/09/catc ... s3-errors/ I should be able to catch these runtimes of this external content to avoid that the error dialogue gets shown in the debug player or that it stops running in the release player.

Link to comment
Share on other sites

Your wish is my command :)

 

I just uploaded a new version of LoaderMax/SWFLoader that gives you a very easy way to handle UncaughtErrorEvents. There's a new "suppressUncaughtErrors" special property that you can set to true and it'll...well...suppress those automatically. Or you can use the new "onUncaughtError" special property to listen for those (or manually add a LoaderEvent.UNCAUGHT_ERROR listener). That way you can handle them in whatever way you want. The ASDocs have been updated as well.

 

For the record, this feature only works if you publish to Flash Player 10.1 or later (that's an Adobe requirement, not something I can control).

 

Does that help?

Link to comment
Share on other sites

Wow, this more then I asked. Really appreciated all the work you did! I will definitely try it out! Really cool.

I just thought you could just give me show tips how to listen to the event :) Lucky me ;)

Link to comment
Share on other sites

Hmm, looks one bit of it ain't working as expected. For example I have the below code with the fluent interface where I am using onUncaughtError. Only this seems to be ignored.

 

           _movieLoader = new SWFLoader( 'greensock_failing_movie.swf',
               new SWFLoaderVars().autoDispose(true).width(1280).height(768).integrateProgress(false).name('module')
                   .suppressUncaughtErrors(false)
                   .autoPlay(false)
                   .container(_moduleContainer)
                   .onError(onMovieLoadError)
                   .onComplete(onMovieLoadCompleted)
                   .onUncaughtError(onMovieUncaughtErrors)
           );

 

Looks like the onUncaughtError is getting ignore in the SWFLoaderVars-class because when I add actual event listener via the normal way it all works fine:

 

           _movieLoader.addEventListener('uncaughtError', onMovieUncaughtErrors );

Link to comment
Share on other sites

It sounds like you didn't update some of the loading-related GreenSock classes like com.greensock.loading.LoaderCore. Please make sure you completely replace your GreenSock files with the new ones. Don't just update SWFLoader. If that still doesn't work, you may need to delete your ASO files in Flash (it's like a cache for classes) because maybe it's holding onto an old version there.

 

I tested your code and it worked fine either way for me.

 

Oh, and make sure you're publishing the parent swf to Flash Player 10.1 or later.

Link to comment
Share on other sites

First of all thanks for your reply. I am still experiencing this problem.

Maybe you can see what I am doing wrong with my little example project?

 

The zip file contains three projects: greensock_loader (loads the movies), the other two: failing_movie and failing_version2 are two simple projects which have a button 'force error' which just throws a runtime error.

 

throw new Error('Unexpected error, oh no!');

 

If I click on the "load movie" button it loads the appropriate movie and if I then click on this "force error" button the error gets raised but without dispatching the LoaderEvent.UNCAUGHT_ERROR event. Because it doesn't dispatch the event I can't suppress the error dialogue. I am not sure what I am doing wrong :(

 

I am targeting 10.2 using Flex SDK 4.5.1. All three projects are made with Flash Builder 4.5.1.

Link to comment
Share on other sites

Aha, the problem is that you set autoDispose to true which means the SWFLoader instance gets disposed as soon as it finishes loading. That SWFLoader instance is the very thing that you attached your uncaughtError listeners to. If the instance is disposed, it removes its own event listeners from the subloaded swf and is made eligible for garbage collection.

 

So if you want to listen for events on your SWFLoader (or have it suppress uncaught errors), don't dispose() it :)

 

Does that clear things up for you?

Link to comment
Share on other sites

Aah, obviously I didn't thought about that! Thanks.

If I need to load the same SWF multiple times per day what's the best way to unload/dispose such SWFLoader? The same question for the DataLoader (for loading text) which needs to be loaded every 10 seconds to check if the contents of files have changed.

 

Off topic: But are you aware of any garbage collection issues between 10.0 and 10.2 (standalone player)?

Link to comment
Share on other sites

Aah, obviously I didn't thought about that! Thanks.

If I need to load the same SWF multiple times per day what's the best way to unload/dispose such SWFLoader? The same question for the DataLoader (for loading text) which needs to be loaded every 10 seconds to check if the contents of files have changed.

I'm not sure I understand your question correctly, but the best way to unload/dispose a SWFLoader (or DataLoader) is to dispose(true) or unload() it. The difference is that unload() only dumps the content but keeps the loader instance itself whereas dispose(true) dumps the content AND the loader instance, releasing it for garbage collection. If you want to reload something, you can load(true) which unloads any existing content first before loading.

 

Off topic: But are you aware of any garbage collection issues between 10.0 and 10.2 (standalone player)?

Nope, I'm not aware of any but I am definitely not an authority on that kind of thing.

Link to comment
Share on other sites

I'm not sure I understand your question correctly, but the best way to unload/dispose a SWFLoader (or DataLoader) is to dispose(true) or unload() it. The difference is that unload() only dumps the content but keeps the loader instance itself whereas dispose(true) dumps the content AND the loader instance, releasing it for garbage collection. If you want to reload something, you can load(true) which unloads any existing content first before loading.

 

Thanks! I will see if it makes a difference. At the moment I am creating new instance of DataLoader every ten seconds for four files to load in the contents and check it against the cache data to determine whether the contents of the file has changed. Maybe I can make a dictionary with filename=DataLoader instance and reuse the same DataLoader.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...