A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: AS2 getTimer combined with if else

  1. #1
    Junior Member
    Join Date
    Jul 2016
    Posts
    11

    AS2 getTimer delay reset issue

    Hi All,

    This is my first post here.
    I am wrestling with an issue where i have 2 buttons which i want to use with a getTimer function.

    If i do not click (no activity) on either button for more than 5 seconds i want it to visit a new frame - _root.gotoAndPlay(50);

    However if i repeatedly multiple click the buttons - i want to remain on the same frame.

    I tried to reset the getTimer to 0 so that when i click once then the counting starts from 0 again.
    "delete onEnterFrame;" does not work if i put it in the 'if' statement.

    I would be very grateful for any help on this one.
    Code below:



    var startTime:Number = getTimer();
    this.onEnterFrame = function() {
    var difference:Number = (getTimer() - startTime) / 1000;

    if (difference < 5) {
    joggleFlowUp.onRelease = function() {
    flowAnimation.prevFrame();
    }
    joggleFlowDown.onRelease = function() {
    flowAnimation.nextFrame();
    }
    }

    else {
    _root.gotoAndPlay(50);
    delete onEnterFrame;
    }
    };
    Last edited by misterbeck; 07-06-2016 at 06:55 AM.

  2. #2
    . fruitbeard's Avatar
    Join Date
    Oct 2011
    Posts
    1,785
    Hi,

    Maybe try using setInterval instead as onEnterFrame is a bit squishy.

    PHP Code:
    stop();

    var 
    difference:Number 0;

    function 
    doTimer():Void
    {
        
    difference += .1;
        
    trace(difference);

        if (
    difference 5)
        {
            
    joggleFlowUp.onRelease = function():Void
            
    {
                
    flowAnimation.prevFrame();
                
    difference 0;
            };
            
    joggleFlowDown.onRelease = function():Void
            
    {
                
    flowAnimation.nextFrame();
                
    difference 0;
            };
        }
        else
        {
            
    clearInterval(theTimer);
            
    _root.gotoAndPlay(50);
        }
    }

    var 
    theTimer setInterval(doTimer100); 
    I am sure you can modify this to your own neeeds.

  3. #3
    Junior Member
    Join Date
    Jul 2016
    Posts
    11
    Quote Originally Posted by fruitbeard View Post
    Hi,

    Maybe try using setInterval instead as onEnterFrame is a bit squishy.

    PHP Code:
    stop();

    var 
    difference:Number 0;

    function 
    doTimer():Void
    {
        
    difference += .1;
        
    trace(difference);

        if (
    difference 5)
        {
            
    joggleFlowUp.onRelease = function():Void
            
    {
                
    flowAnimation.prevFrame();
                
    difference 0;
            };
            
    joggleFlowDown.onRelease = function():Void
            
    {
                
    flowAnimation.nextFrame();
                
    difference 0;
            };
        }
        else
        {
            
    clearInterval(theTimer);
            
    _root.gotoAndPlay(50);
        }
    }

    var 
    theTimer setInterval(doTimer100); 
    I am sure you can modify this to your own neeeds.

  4. #4
    Junior Member
    Join Date
    Jul 2016
    Posts
    11
    Awesome.

    Thank you so much Fruitbeard. Quickly installed the code and it works like a dream... and i actually understand it!

    cheers

Posting Permissions

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




Click Here to Expand Forum to Full Width

HTML5 Development Center