Tieme
Tieme

Reputation: 65389

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

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.

Upvotes: 1

Views: 3980

Answers (3)

jkarretero
jkarretero

Reputation: 471

Simply do this:

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

Upvotes: 1

Jorjon
Jorjon

Reputation: 5434

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

Upvotes: 0

DanielB
DanielB

Reputation: 20230

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.

Upvotes: 0

Related Questions