Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Feb 2006
    Posts
    55
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Make a button do something after a a certain time

    Hi Guys,

    I have a button in Flash, i am still using Flash 8 and ActionScript 2 as thats what im used to

    When i click the button, i want it to go and and play a different Frame so i have:


    on (press){
    gotoAndPlay(2);
    }


    But i want it to gotoAndPlay frame 2 only after 3 seconds of clicking the button.

    Ideally, i would like that when the button is clicked, it will gotoAndPlay frame 2, but if you click the button and hold it for 3 seconds, it will gotoAndPlay frame 3.

    Is it even possible to do that?

  • #2
    New Coder
    Join Date
    Feb 2006
    Posts
    55
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Ok, i made some progress, i came up with this:


    on (press) {
    // get start time
    mousedown = getTimer();
    }

    on (release) {
    // set time to hold down
    timer = 3000;
    // get finish time
    mouseup = getTimer();
    // calculate how long the button was pressed
    difference = mouseup - mousedown;

    if (difference >= timer) {
    gotoAndPlay(2);
    } else {
    gotoAndPlay(3);
    }

    }


    However, the problem i have now is that the button has to be released. I want to go to frame 2 while the button is still being pressed, not aftre it is released?

    i have played with putting the executable code in the on (press) function but then i cannot play frame 3 when the button is released.

    Any Ideas would be greatly appreciated

  • #3
    Senior Coder gnomeontherun's Avatar
    Join Date
    Sep 2007
    Location
    Houston
    Posts
    2,846
    Thanks
    10
    Thanked 238 Times in 229 Posts
    Please put code between [ CODE ] brackets.

    Code:
    on (press) {
    // get start time
    mousedown = getTimer();
    gotoAndStop(2);
    }
    
    on (release) {
    // set time to hold down
    timer = 3000;
    // get finish time
    mouseup = getTimer();
    // calculate how long the button was pressed
    difference = mouseup - mousedown;
    
    if (difference >= timer) {
    gotoAndPlay(3);
    }
    
    }
    Can't say I really understand why or what you are doing here...
    jeremy - gnomeontherun
    Educated questions often get educated answers, and simple questions often get simple answers.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •