Skip to main content
This topic has been closed for replies.
Correct answer Ned Murphy

Are you marking your response as correct because you solved it?

Assuming you didn't, my guess is that you want to have the lines where you add the ENTER_FRAME lsistener and start the timer to be executed by some control in your menu.  As you have them now they will start immediately.  Place them inside a function and have a button in your menu call them... something similar to the following would be a starting point...

startPlayingBtn.addEventListener(MouseEvent.CLICK, startPlaying)

function startPlaying(evt:MOuseEvent):void {

      addEventListener(Event.ENTER_FRAME,OnEnter)

      myTimer.start();

}

1 reply

Ned Murphy
Legend
September 26, 2013

I'll have to assume that some of your 'game starts' mentions are before the playing begins and others are when playing begins.

To stop the game from playing right away you need code that holds off doing that - the menu you mention should be where the playing in initiated.  What code starts the playing of the game now?

Participant
September 26, 2013

This is the code of the 'Main Game' scene.

import flash.events.Event;

addEventListener(Event.ENTER_FRAME,OnEnter)

Mouse.hide();

stop();

var myTimer:Timer = new Timer(1000,15)

var time = 0;

myTimer.start();

myTimer.addEventListener(TimerEvent.TIMER,timerHandle)

function timerHandle(e:TimerEvent){

                    txt_time.text = time;

                    time++;

          }

function OnEnter(e:Event)

{

 

          Louis.x = mouseX;

          Louis.y = mouseY;

 

          Owen1.y = Owen1.y + 3;

          Owen2.y = Owen2.y + 3;

          Owen3.y = Owen3.y + 4;

          Owen4.y = Owen4.y + 1.5;

          Owen5.y = Owen5.y + 4;

          Owen6.y = Owen6.y + 4;

 

 

          if(Owen1.y > 640)

          {

                              Owen1.y = -100;

 

                              var a:Number;

 

                              a = Math.random();

 

                              trace (a);

 

 

                              if(a < 0.5)

                              {

                                        Owen1.x = 100;

                              }

                              else

                              {

                                        Owen1.x = 700;

                              }

 

 

                        if(stage.frameRate <= 120)

                              {

                                        stage.frameRate = stage.frameRate +10;

                              }

 

          }

 

          if(Owen2.y > 640)

          {

                              Owen2.y = -100;

          }

 

          if(Owen3.y > 640)

          {

                              Owen3.y = -100;

 

          }

 

          if(Owen4.y > 640)

          {

                              Owen4.y = -100;

          }

 

          if(Owen5.y > 640)

          {

                              Owen5.y = -100;

          }

 

          if(Owen6.y > 640)

          {

                              Owen6.y = -100;

          }

 

 

          if (Louis.hitTestObject(Owen1))

          {

 

                    removeEventListener(Event.ENTER_FRAME,OnEnter);

                    gotoAndStop(1,"The End");

          }

          if (Louis.hitTestObject(Owen2))

          {

 

                    removeEventListener(Event.ENTER_FRAME,OnEnter);

                    gotoAndStop(1,"The End");

          }

          if (Louis.hitTestObject(Owen3))

          {

 

                    removeEventListener(Event.ENTER_FRAME,OnEnter);

                    gotoAndStop(1,"The End");

          }

          if (Louis.hitTestObject(Owen4))

          {

 

                    removeEventListener(Event.ENTER_FRAME,OnEnter);

                    gotoAndStop(1,"The End");

          }

          if (Louis.hitTestObject(Owen5))

          {

 

                    removeEventListener(Event.ENTER_FRAME,OnEnter);

                    gotoAndStop(1,"The End");

          }

 

 

          if (Louis.hitTestObject(Owen6))

          {

 

                    removeEventListener(Event.ENTER_FRAME,OnEnter);

                    gotoAndStop(1,"The End");

          }

 

 

 

}

I know its not the tidiest or the best.

Its my first go.

Ned Murphy
Ned MurphyCorrect answer
Legend
September 26, 2013

Are you marking your response as correct because you solved it?

Assuming you didn't, my guess is that you want to have the lines where you add the ENTER_FRAME lsistener and start the timer to be executed by some control in your menu.  As you have them now they will start immediately.  Place them inside a function and have a button in your menu call them... something similar to the following would be a starting point...

startPlayingBtn.addEventListener(MouseEvent.CLICK, startPlaying)

function startPlaying(evt:MOuseEvent):void {

      addEventListener(Event.ENTER_FRAME,OnEnter)

      myTimer.start();

}