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 derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

on (press) timing issue... 1

Status
Not open for further replies.

MartinCouture

Technical User
Feb 16, 2002
57
CA
I would like a button to do

press -> do A

Press longer than 1 second -> do B

All with the same button.

The problem is that on(press) doesn't care if it's 1 second or an hour. My solution was to try with:

on (release) {
if (!long_press) {
-== DO A STUFF ==-
}
}
on (press) {
mydate = new Date();
time_in_sec = int(mydate.getTime()/1000);
start_press = time_in_sec;
x = 0;
while (x<2) {
mydate = new Date();
time_in_sec = int(mydate.getTime()/1000);
x = time_in_sec-start_press;
if (x>1) {
long_press = true;
-== DO B STUFF ==-
}
}
}


Any hints out there. It's for a panel in the airplane and lots of the buttons do different actions depending if it's a short press or a long press.

Thanks
-----------------
[flush]
 
Make a movieClip to deal with it instead of a button, and put these actions on it:
Code:
onClipEvent (mouseDown) {
    if (this.hitTest(_root._xmouse, _root._ymouse, true)) {
        init = false;
        timed = true;
    }
}
onClipEvent (mouseUp) {
    if (this.hitTest(_root._xmouse, _root._ymouse, true)) {
        if (time < 2000) {
            trace (&quot;This is a short one - &quot; + time/1000 + &quot; seconds!&quot;);
        } else {
            trace (&quot;This is a long one - &quot; + time/1000 + &quot; seconds!&quot;);
        }
    }
    timed = false;
    time = 0;
}
onClipEvent (enterFrame) {
    if (timed == true) {
        if (init == false) {
            startTime = getTimer ();
            init = true;
        }
        time = getTimer() - startTime;
    }
}
Run this in &quot;TEST MOVIE&quot; and you'll see trace messages appear in the OUTPUT window. They'll tell you if it's a short click or a long click, and how many seconds it was.

All you need to do is insert your own actions where the 2 trace statements are.
 
Thank you very much !

Nice work.

;-) -----------------
[flush]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top