Skip to main content
January 1, 2011
Answered

How do I reset and start another game.

  • January 1, 2011
  • 1 reply
  • 785 views

Hello

Please can someone help, I have spent several days on this and still can't get it to work.

The code below is ok, I am playing a bowling game using the keyboard and timer with a text readout of the elapsed time, the bowl moves a set number of pixels on the screen.  whilst in full screen mode I would like to click a start/play button on the screen to start the game and timer again, everything is in frame 1.  Also I would like the game to just accept the keycode 77 and keyboard event (2 events only to move the bowl) and then wait for the start/play button click.

Thanks

Mick

import flash.utils.Timer;
import flash.events.MouseEvent;
import flash.events.TimerEvent;

var totalTime:Number = 0;
var startTime:Number;
//stop();
var bowlTimer:Timer = new Timer(1,6000);

//startButton.addEventListener(MouseEvent.CLICK, startTimer);

bowlTimer.addEventListener(TimerEvent.TIMER, moveBowl);

//bowlTimer.addEventListener(TimerEvent.TIMER_COMPLETE, endTimer);

/*function startTimer(e:MouseEvent):void
{
clockTimer.start();
trace("Timer started");
startButton.visible = false;
}*/

function moveBowl(e:TimerEvent):void
{
myBowl.x = myBowl.x + 70;
trace("Timer cycle expired");
}

/*function endTimer(e:TimerEvent):void
{
trace("Timer finished");
}
*/
stage.addEventListener(KeyboardEvent.KEY_DOWN,keyDownHandler);

var myKeyBoolean = false;

function keyDownHandler(event:KeyboardEvent)
{

if (event.keyCode == 77)
{

  bowlTimer.start();
  startTime = getTimer();

}
else if (myKeyBoolean == false)
{

  bowlTimer.stop();
  totalTime +=(getTimer()-startTime)/1;

  yourTF.text = Math.round(totalTime).toString();
}// add yourTF to the stage

  }

This topic has been closed for replies.
Correct answer Ned Murphy

While you should wait to see if someone provides a code-based solution that will slide into what you now have, one of the easiest ways to realize a reset is to build your design into frame 2, keeping frame 1 devoid of any controlled objects/code (just graphics to avoid a blank flash), and when you want to reset you use gotoAndPlay(1).  That should return you to initial conditions all around.

1 reply

Ned Murphy
Ned MurphyCorrect answer
Legend
January 1, 2011

While you should wait to see if someone provides a code-based solution that will slide into what you now have, one of the easiest ways to realize a reset is to build your design into frame 2, keeping frame 1 devoid of any controlled objects/code (just graphics to avoid a blank flash), and when you want to reset you use gotoAndPlay(1).  That should return you to initial conditions all around.

January 1, 2011

Hello, Thanks for the reply.

I put the code onto frame 20 and added the gotoAndPlay (1), the code played, I then clicked the button which reset the playhead to frame 1 , however the code didn't play a second time ?

Any idea why ?

Thanks for your help.

Mick

myButton.addEventListener(MouseEvent.CLICK, fl_ClickToGoToAndPlayFromFrame_2);

function fl_ClickToGoToAndPlayFromFrame_2(event:MouseEvent):void
{
gotoAndPlay(1);
trace("btn_myButton");
}

January 1, 2011

Hello

By chance I hit the enter key after the movie clip had played and it went back to the position I wanted without any code !

Result.

Thanks anyway

Mick