Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

long press on button

Status
Not open for further replies.

radiostar

Programmer
Feb 23, 2004
14
AU
Hey everyone,

I'm wondering if someone can help me out with this one. What I want to do is create a button that performs the following:

- press then release = Function1;
- press and hold = Function2;

I have to make it work on a Flash 5 player so using setInterval is unfortunately out. Any suggestions?

Here's what I've tried to do with the button, which ain't workin:

on(press) {

//Set the timer
SetTimer = getTimer();

//Set timer on to true
TimerOn = true;

do {
if (getTimer() < SetTimer+1500){

//wait and do nothing

} else {
//Set timer on to false
TimerOn = false;

//Call Function 2
Function2();
}
} while(TimerOn == true);

}

on(release) {
TimerOn = false;
Function1();
}


The problem I'm getting is that the 'on(release)' action is not happening until the 'do while' statement in the 'on(press)' action evaluates to false. So basically Function2 is executed and then the 'on(release)' actions are executed.

I would be extremely grateful for any help.

Cheers,
Radiostar


 
The do/while loop is executing on one frame so it's not really checking the timer at all. To keep checking the elapsed time you'll have to use a clipEvent:

Code:
onClipEvent(enterFrame){
if(timerOn){
 if (getTimer() < SetTimer+1500){
//do stuff
    }
  }
}

Where timerOn and SetTimer are set from your button as in your code above. The clipEvent runs every frame and will start to evaluate the elapsed time only when the button is pressed and the timerOn condition becomes true.
 
Thank You! It works like a charm. There is actually only one frame in the mc so it was checking the timer, however it just stayed in the do/while loop until the loop evaluated to false. So obviously not the way to go about it.

Thanks again for your help, you're a legend! :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top