Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

help with making a back button

New Here ,
Jul 22, 2013 Jul 22, 2013

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();

                    }

TOPICS
ActionScript
1.5K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jul 22, 2013 Jul 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 23, 2013 Jul 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?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jul 23, 2013 Jul 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. 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 25, 2013 Jul 25, 2013

sorry for delay i get this:

[object Game]

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jul 25, 2013 Jul 25, 2013

That indicates you are telling the Game object to gotoAndStop.  If the Game object is not the intended timeline, then you need to target that timeline.

Try changing that line to be:  MovieClip(root).gotoAndStop(1);  and see if it helps.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 25, 2013 Jul 25, 2013

if i click on the back button now i get:

TypeError: Error #1034: Type Coercion failed: cannot convert flash.display::Stage@33a7f81 to flash.display.MovieClip.

          at com.alienattack::Game/back()

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jul 25, 2013 Jul 25, 2013

How does the Game class file relate to the main file?  Is it imported and instantiated or is it assigned as the document class?

Does the main file use the timeline such that going to frame 1 would restart things, or is using gotoAndStop(1)  just a guess at resetting things?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 25, 2013 Jul 25, 2013

What I want the function to do is go to frame 1 but that is not the main menu the menu is a movie clip but that is easy to add. first I need to get to frame one

The game class file is called when you click on play of the start menu movie clip.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jul 25, 2013 Jul 25, 2013

Frame 1 of what timeline?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 26, 2013 Jul 26, 2013
LATEST

The main timeline

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines