Skip to main content
Participant
March 25, 2013
Question

Click a button a certain amount of times within a certain amount of time?

  • March 25, 2013
  • 1 reply
  • 447 views

So can someone give me an example of  having to click a button 20 times within 10 seconds in order to move on to the next scene and if not restarts and let's you try again. Let's say the button has an instance name of the theButton. This means that I also need a timer and because I am a newbie I'm not sure how to do all of that, thanks!

This topic has been closed for replies.

1 reply

Ned Murphy
Legend
March 25, 2013

Are you asking someone to write your code for you?  What have you tried so far that is not working?

Participant
March 25, 2013

This is what I was thinking but I know there's probably a lot wrong with it!

var numClicks = 0; //number of times you click on button

theButton.addEventListener(MouseEvent.MOUSE_DOWN, buttonClicks);function buttonClicks(event:MouseEvent):void {

numClicks++

}

var nCount:Number = 10;

var myTimer:Timer = new Timer(1000, nCount);

timer_txt.text = nCount.toString();                                                                             //making the timer

myTimer.start();

myTimer.addEventListener(TimerEvent.TIMER, countdown);

function countdown(e:TimerEvent):void

{

          nCount--;

          timer_txt.text = nCount.toString();

}

if(timer_txt.text == 0 && numClicks==20) {

gotoAndPlay(1, "scene 2");

}                   

else

{ gotoAndPlay(1, "scene1");}                           //an if statement to see if the timer is at zero and you've got enough clicks, otherwise restart

Inspiring
March 25, 2013

rewrite some of the passages and you should be  good:

theButton.addEventListener(MouseEvent.CLICK, buttonClicks);

function buttonClicks(event:MouseEvent):void {

numClicks++;

//first click starts the timer

if(numClicks==1){

myTimer.start();

}

//evaluate if has already run out

if(numClicks==20){

if(myTimmer.running){

gotoAndPlay(1, "scene 2");

}

else{

gotoAndPlay(1, "scene1");

}

}

}