Skip navigation
schefz
Currently Being Moderated

Timing how long a button is pressed down for

Oct 9, 2007 6:22 PM

Hello all. I was wondering if I could get some help on this topic. I am trying to figure out a way to have a button jump to a certain frame if pressed but then also jump to a different frame if the button is held down for a certain time period, lets say 2 seconds. I am assuming I would have to use the Timer() function. My logic is as follows;
on(press){
start timer()
If timer() == 2 secs
gotoAndStop(frame15);
ELSE
gotoAndStop(frame 37);
}

any suggestions??
 
Replies
  • Currently Being Moderated
    Oct 9, 2007 6:34 PM   in reply to schefz
    Are you working in AS3? because you can't add script to a button or MC in that way, and there is no Timer() function in AS2. You would need to use setInterval like so:
     
    |
    Mark as:
  • Currently Being Moderated
    Oct 9, 2007 6:44 PM   in reply to clbeech
    in addition to clbeech's code, don't forget to clear the interval if the user releases the mouse button.

    and by the way, this is AS2 code.
     
    |
    Mark as:
  • Currently Being Moderated
    Oct 9, 2007 7:10 PM   in reply to schefz
    yes it will be possible. communicating exactly what you're after can sometimes be the difficult part.
    think about answers for these questions.
    what do you want to happen:
    a. at the point where the user clicks the mouse
    b. at the point where the user releases the mouse
    c. two seconds after the user clicks the mouse, if the user has not released the mouse

    when you have clear answers to these questions the code will come naturally.
     
    |
    Mark as:
  • Currently Being Moderated
    Oct 9, 2007 7:34 PM   in reply to schefz
    i probably would advise a more self-explanatory variable name than 'counter' but otherwise, wax on!
     
    |
    Mark as:
  • Currently Being Moderated
    May 26, 2012 4:08 PM   in reply to schefz

    Hi ! I made it work another way. Now I'm looking for a AS3 version...

     

    http://forums.adobe.com/thread/1012244

     

    Thanks !

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points