AS3.0 Replay the whole movie (*SWF file)

2020-04-18 06:03发布

问题:

I made a small game in Actionscript 3.0 and flash.

When the player wins the game or is 'game over' the player should have a option to replay the game.

So my question is: Is there a way to replay the whole movie with Actionscript? I know, i could reset the timeline back to 0, and re-instantiate all the classes, movieclips, var's ect... but i was wondering if anyone knows a easier solution.

回答1:

You can remove the swfObject and add it again. Look here. This is the swfObject reference.



回答2:

Simply do this:

import flash.net.*;
//...
navigateToURL(new URLRequest(stage.loaderInfo.url), "_level0");


回答3:

Reload the page, where you've embedded the swf into, may be the easiest way.

The programmers way would be to encapsulate your whole application into a single class (extending Sprite or MovieClip) which will be attached to the stage. For restarting the game you could simply remove that instance from the stage and add a newly created onto the stage.

Or make a loader swf, that loads your game. Then if the game should be restarted, discard (unload) the instance and load it again.

Its hard to tell you what you can do, if we don't know, how your project is structured.