1 Reply Latest reply on May 13, 2014 4:36 AM by Ned Murphy

    How do I make a Game Over Page or frame in flash

    Beginning

      I am having trouble trying to do my project(game) as I do not know how to end the game using the bullet like when the bullet reach 0, it will be game over and redirect the game to the game over page or frame in flash.

      I need the game to end with when the bullet reach 0, it will redirect  to the game over frame or page.

      I need it to show the score at the Game over page so please teach me the coding and how do I do it.

      PS I am using actionscript 3.0 and using adobe flash cs6 and please tell me where to put the code and how to make it.Thanks you to the fullest

      This is my main coding.

       

      package  {

       

        import flash.display.MovieClip;

        import flash.events.MouseEvent;

        import flash.ui.Mouse;

        import flash.net.URLRequest;

        import flash.net.URLLoader;

        import flash.events.Event;

        import flash.utils.Timer;

        import flash.events.TimerEvent;

       

        public class main extends MovieClip {

       

        var req:URLRequest;

        var loader:URLLoader;

        var cursor:Cursor = new Cursor();

        var gameTimer:Timer = new Timer(2000,10); // ,20 is the limit of the time

        var score:Number;

        var bullet:Number;

       

        public function main() {

        stop();

        Mouse.hide();

        cursor.mouseEnabled = false;

        stage.addEventListener(MouseEvent.MOUSE_MOVE,moveMouse);

        instruBtn.addEventListener(MouseEvent.CLICK,goinstr);

        startBtn.addEventListener(MouseEvent.CLICK,goGame);

        addChild(cursor);

        }

       

        function goGame(evt:MouseEvent):void

        {

        gotoAndStop(15);

        gameTimer.addEventListener(TimerEvent.TIMER,startgame);

        gameTimer.addEventListener(TimerEvent.TIMER_COMPLETE,gameOver);

        stage.addEventListener(MouseEvent.CLICK,minus);

        gameTimer.start();

        score = 0;

        scoreTxt.text = score.toString();

        gameOverTxt.visible = false;

        bullet = 21;

        bulletTxt.text = bullet.toString(); //the way is to put "" + count;

        }

       

        function minus(evt:MouseEvent):void

        {

        bullet --;

        bulletTxt.text = "Bullet=" + bullet;

        }

       

        function updatecount():void

        {

          bullet --;  //count = count - 1

          bulletTxt.text = "Bullet=" + bullet;

        }

       

        function startgame(evt:TimerEvent):void

        {

        var duck:Duck = new Duck();

        duck.x =  stage.stageWidth;

        duck.y = Math.random() * stage.stageHeight;

        addChild(duck);

        addChild(cursor);

       

        }

       

        function setScore():void

        {

        score++; //score = score + 1

        scoreTxt.text  =  "Score=" + score;

        }

        function gameOver(evt:TimerEvent):void

        {

        gameOverTxt.visible = true;

        gameOverTxt.text = "Game Over!";

        }

       

        function goinstr(evt:MouseEvent):void

        {

        gotoAndStop(12);

        backBtn.addEventListener(MouseEvent.CLICK,gohome);

        req = new URLRequest("Instruction.txt");

        loader = new URLLoader();

        loader.addEventListener(Event.COMPLETE,fileLoaded);

        loader.load(req);

        }

       

        function moveMouse(evt:MouseEvent):void

        {

        cursor.x = this.mouseX;

        cursor.y = this.mouseY;

        }

       

       

        function fileLoaded(evt:Event):void

        {

        txtlabel.text = loader.data;

        }

        function gohome(evt:MouseEvent):void

        {

        gotoAndStop(1);

        instruBtn.addEventListener(MouseEvent.CLICK,goinstr);

        startBtn.addEventListener(MouseEvent.CLICK,goGame);

        }

        }

       

      }

      This is my duck or movieclip actionscript.Just in case you may need it.

      package  {

       

        import flash.display.MovieClip;

        import flash.utils.Timer;

        import flash.events.TimerEvent;

        import flash.events.MouseEvent;

       

        public class Duck extends MovieClip {

       

       

        var moveDuck:Timer = new Timer(10);

        var speedX:Number;

       

       

        public function Duck() {

       

       

        this.addEventListener(MouseEvent.CLICK,KillDuck);

        moveDuck.addEventListener(TimerEvent.TIMER,ducksmove);

        moveDuck.start();

        speedX = 5;

        }

              function ducksmove(evt:TimerEvent):void

        {

        this.x -= speedX;

        if (this.x <=0)

        {

        moveDuck.stop();

        moveDuck.removeEventListener(TimerEvent.TIMER,ducksmove);

        this.parent.removeChild(this);

        }

        }

       

       

        function KillDuck(evt:MouseEvent):void

        {

        var p:MovieClip = this.parent as MovieClip;

        p.setScore();

        this.removeEventListener(MouseEvent.CLICK,KillDuck);

        this.parent.removeChild(this);

        moveDuck.removeEventListener(TimerEvent.TIMER,ducksmove);

        }

      }

      }