Note that there are some explanatory texts on larger screens.

plurals
  1. POTrouble resetting objects in Actionscript 3 / Flash CS5
    text
    copied!<p>I'm making a simple platform game in Flash CS5 and Actionscript 3.0. When the player loses all their lives, I want it to redirect the player to a "Game over" screen where they can select a "Try again" button to restart the game.</p> <p>I'm having trouble finding a way to do this. I've been trying to accomplish my goal by doing the following:</p> <ul> <li>Set everything (player, background, etc) to visible = false</li> <li>Set "Game over" movie clip to visible = true (it is invisible during gameplay)</li> <li>Have the button in the "Game over" movie clip hide the movie clip then re-show all the gameplay elements</li> <li>Reset position of player to start, set score to 0, lives to 3, etc..</li> </ul> <p>It's probably not a very good way of doing this but if it works, then I'm happy. I just want the "Game over" screen to show briefly and if the player clicks the "try again" button, they can play from the start.</p> <p>Now, the problem with my implementation of the above is that when I set all the gameplay elements to visible = true after having them set to false, the game has stopped.. keyboard input doesn't reactivate and the game elements are shown but aren't active. Is there something about the visible attribute I don't know? Does it mess with the "state" of an object?</p> <p>Here's some snippets of code from the Actionscript file...</p> <pre><code>if(lives &gt;= 0) { //print number of lives } else { gameOverFlag= true; //hide game objects, show game over menu Coins.visible = false; Platforms.visible = false; Background.visible = false; StartPosition.visible = false; thePlayer.visible = false; GameOver.visible = true; //this is the movie clip with the "Game over" text and "Try again" button in GameOver.TryAgainButton.addEventListener(MouseEvent.CLICK, playagain); } function playagain(event:MouseEvent):void { //start game again Coins.visible = true; Platforms.visible = true; Background.visible = true; StartingPosition.visible = true; thePlayer.visible = true; } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload