Copy link to clipboard
Copied
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();
}
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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?
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
sorry for delay i get this:
[object Game]
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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()
Copy link to clipboard
Copied
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?
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
Frame 1 of what timeline?
Copy link to clipboard
Copied
The main timeline
Find more inspiration, events, and resources on the new Adobe Community
Explore Now