A reset for your SWF

Back in the AS2 days there was a handy trick in order to get a complete reloading of a SWF from within itself:

getURL(_url, "_level0");

That changed when AS3 came around. Just recently I was asked to create a reset for a fairly complex SWF that had lots of variables and data in it. It wouldn’t run in a browser, etc. but as a standalone. Instead of creating a method that would reset all those variables, etc. I found it’s just as easy in AS3. Something like this:

import flash.net.*;
private function resetMe(event:MouseEvent):void {
    var url:String = stage.loaderInfo.url;
    var request:URLRequest = new URLRequest(url);

Works a treat. If I keep adding new variables, etc. to the SWF I won’t have to worry about adding those to a reset method, etc.

Update (February 8th, 2011 : 9:00 AM EST)

Well, it works for a SWF, but if you’re deploying a projector it doesn’t want to work correctly. It loads nothing in the projector’s viewport. It works if you launch the SWF as a standalone or in a browser. Fooey ;)

Related Posts Plugin for WordPress, Blogger...

5 thoughts on “A reset for your SWF

  1. Pingback: Tweets that mention A reset for your SWF // Imagineric -- Topsy.com

  2. Richard

    I read this and scoffed, “That can’t be right, he must mean loadMovieNum for his first example, and I bet the second example doesn’t work at all!”

    I looked up navigateToURL and saw that the second argument is supposed to be a reference to a browser window or HTML frame.

    So I tried breaking it in every way I could think of, but this does seem to work. Removing the second argument doesn’t work, changing the second argument to “bob” or “_level1″ doesn’t work, but “_level0″ does work.

    Since it appears to be undocumented by Adobe it could break at any time, but I’ll give you credit, it looks like it works!

  3. Collin Reisdorf

    Still works in Flashplayer 11.1, I’m pretty sure it’ll always work since the flash player just using it’s ability to load external swf content, but targeting the base movie clip (_level0)


Leave a Reply

Your email address will not be published. Required fields are marked *

+ 3 = nine

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>