Jump to content


Reset loaded swf after use?

Moderator Tag

Recommended Posts

I can't seem to find an easy way to do this and just wondering if I missed something... I have a main swf that I'm loading multiple child swf's into, then depending on the section of the project you're in, I just addChild/removeChild with Loadermax's getContent. Before removing any of the child swf's, I'm manually calling a transitionOut() -> destroy() method in the one that's currently on stage to clean up the listeners, remove dynamically generated objects, etc. There are a bunch of clips on the timeline's of these child swf's that I'll need to reset to their original positions/alpha's/etc and I was wondering if there was a way to just reinstantiate the swf instead of having to keep track of all the properties that changed with these stage movieclips?


The closest thing I can think of is to just preload all the swf's with loadermax, then separately just load them again when I need them, giving me the ability to unloadAndStop on the child swf before unloading, but it kinda defeats the purpose of loading them all up front, right? Ideally, the reason to load up front is to make for seamless transitions between swf's...

Link to comment
Share on other sites

Yep, you're correct - as far as I know, Flash doesn't have a way to tell a swf/MovieClp to wipe out all of its changed properties, reset back to the beginning state and start over. Of course there's gotoAndPlay(1), but that doesn't reset variables/properties that were changed with ActionScript.


You have 3 options as I see it:


1) Build your child swf so that it has a "restart()" or "init()" method (or whatever) that handles all of that resetting manually. This is a pain, I know, but then you can just call that method anytime you want and get the result you're after.


2) unload() the SWFLoader and load() it again. Technically the swf should be cached on the hard drive after the first load, so subsequent loads would be very fast.


3) Load your swf with a DataLoader that has its format special property set to "binary" which will load it as a ByteArray. Then, anytime you want to make another copy of that swf, you create a Loader and use loadBytes() like this:


var loader:DataLoader = new DataLoader("assets/child.swf", {name:"swf", format:"binary", onComplete:completeHandler});

function completeHandler(event:LoaderEvent):void {
var swf1:Loader = new Loader();

//make another copy...
var swf2:Loader = new Loader();


NOTE: There are some potential security issues with technique #3 (Google loadBytes and security), so be careful if you don't trust the subloading swf.


Technique #3 also doesn't have the auto sizing and cropping benefits that SWFLoader offers (in case that's important to you).

Link to comment
Share on other sites

Thanks for the info Jack. You'd almost think Adobe would have a reset functionality built-in perhaps. If you code on the timeline, you can just gotoAndPlay from frame 1 and effectively do the same thing if your code is on the timeline. Instead, if it's in a document class, guess there's no easy way.


Anyway, thanks for the help and thanks for making some awesomely useful classes for us all!

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.