質問

I made a Flash project in FlashDevelop to create an Ad.

The Preloader is setup by making use of the Additional Compiler argument:

-frame=NameOfLabel,NameOfMainClass

My main class is simply called "Main", at the top / default package level.

So frame #1, being the Preloader portion of the SWF, has:

  • Very few bitmaps, vector-graphics and text (to stay under 50kb);
  • A YouTube video player in the center (does not count in the filesize limit);

The frame #2 has everything else (the Main class basically embeds all it's dependencies). This includes:

  • Assets from precompiled SWF (Bitmaps, Symbols, Fonts, XML data);
  • All classes imported (this is recursive for every classes importing other classes);

Now my big problem is, my client requested the "replay" functionality long after I've completed 99.9% of the project.

I have the project more-or-less broken into different states (Intro, Ready, SlideMenu, etc.), but I'm not sure how I can easily reset the Flash movie back to the very beginning (where it was preloading and showing the YouTube video).

The easy solution would be to simply call an ExternalInterface JavaScript method that would refresh the Flash container, BUT I don't think I have control over what's going on the HTML / JavaScript side.

Is there an easy way to invoke a replay function from AS3?

役に立ちましたか?

解決 2

The following seems to do the trick!

private function onReplayClick(e:MouseEvent):void {
    var theStage:Stage = this.stage; //Temporarly store the stage.

    //Kill any animations happening:
    TweenMax.killAll(); //3rd party, may not be applicable for you :P

    //Remove ALL containers / child DisplayObjects
    SpriteUtils.recursiveRemove(theStage); //custom-made
    // (this object is no longer attached to the stage at this point)

    //Nullify any Singleton / Static variables:
    Main.INST = null;

    // Load the 'bytes' of the current SWF in a new Loader, then...
    // add it to the stage
    var swf:Loader = new Loader();
    swf.loadBytes( theStage.loaderInfo.bytes );
    theStage.addChild( swf );
}

By doing a deep recursive cleanup of the DisplayObjects, and any static variables (like Singleton instances), it leaves you with a blank stage.

After that, you can instantiate a new Loader that will load the SWF itself via the current LoaderInfo's bytes property.

Add the Loader to the Stage, and you're up and running again!

他のヒント

Would not simply going back to frame 1 do the trick ?

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top