Skip to main content
Known Participant
July 22, 2013
Question

help with making a back button

  • July 22, 2013
  • 1 reply
  • 1526 views

hi

in a game im making i have a start menu that then when you click play goes to the game after playing the game, when you die a game over screen appears with a play again button in it i want to put a back button to go to the first frame.

the way this is set up is that the game over menue is a movie clip with the play again button in it i want to have a back movie clip to make it go to the first frame

gotoAndStop(1) dosent seem to work or mabye i am doing it wrong

this my game class file as the game over menu does not have a class file:

package com.alienattack{

          import flash.display.MovieClip;

          import flash.events.Event;

          import flash.utils.Timer;

          import flash.text.TextField;

          import flash.text.TextFormat;

          import flash.display.Stage;

          public class Game extends MovieClip          {

                    static var ship:MovieClip;

                    static var enemyShipTimer:Timer;

                    static var scoreText:TextField;

                    static var score:Number;

                    static var healthMeter:HealthMeter;

                    static var enemyHealthMeter:EnemyHealthMeter;

                    static var gameOverMenu:GameOverMenu;

                    static var powerUpTimer:Timer;

                    static var miniBossTimer:Timer;

                    static var RocketShipTimer:Timer;

                    var bossCountdown:Number;

                    static var Bombtimer:Timer;

                    private var _stage:Stage;

                    static var backgroundMusic = new BackgroundMusic();

                    var Bullet;

                    public function Game(){

                                 this.addEventListener(Event.ADDED_TO_STAGE,init);

                    }

                    function init(e:Event):void{

                              _stage=stage;

                              KeyClass.initialize(stage);

                              stage.focus = this;

                              ship = new Ship();

                              ship.x = 300;

                              ship.y = 150;

                              _stage.addChild(ship);

                              enemyShipTimer = new Timer(2000);

                              enemyShipTimer.addEventListener("timer", sendEnemy);

                              enemyShipTimer.start();

                              RocketShipTimer = new Timer(3500);

                              RocketShipTimer.addEventListener("timer", sendEnemyRocket);

                              RocketShipTimer.start();

                              resetScore();

                              gameOverMenu = new GameOverMenu();

                              gameOverMenu.x = 0;

                              gameOverMenu.y = 0;

                              addChild(gameOverMenu);

                              gameOverMenu.visible = false;

gameOverMenu.playAgainButton.addEventListener("mouseDown", newGame); (this is where i think the play again button is but how would i make it so it when to the first frame)

            backgroundMusic.play(0,1000);

                    }

                    static function gameOver()

                    {

                              gameOverMenu.visible = true;

                              enemyShipTimer.stop();

                              miniBossTimer.stop();

                              RocketShipTimer.stop();

                              Bombtimer.stop();

                              powerUpTimer.stop();

                              for (var i in EnemyShip.list)

                              {

                                        EnemyShip.list.kill();

                            }

                    }

                    function newGame(e:Event)

                    {

                              gameOverMenu.visible = false;

                              ship.visible = true;

                              ship.x = 300;

                              ship.y = 150;

                              ship.takeDamage(-ship.maxHealth);

                              ship.addEventListener("enterFrame", ship.move);

                              resetScore();

                              enemyShipTimer.start();

                              miniBossTimer.start();

                              RocketShipTimer.start();

                              Bombtimer.start();

                              powerUpTimer.start();

                    }

This topic has been closed for replies.

1 reply

Ned Murphy
Legend
July 22, 2013

The play again button calls the newGame function, so the new game function is probably where you want to have the gotoAndStop(1), assuming that stopping at 1 is where the game starts.

Known Participant
July 23, 2013

hi

i make a new function back and change the new game to back but the screen does not go to the first frame

gameOverMenu.backbutton.addEventListener("mouseDown", back);

function back(e:Event)

                    {

                              gotoAndStop(1);

                    }

any help?

Ned Murphy
Legend
July 23, 2013

Put a trace in that function to see if it is executing when you click the button. 

Use   trace(this);   within that function to see if you are actually targeting the timeline you think you are.