Skip navigation
Lemon Video
Currently Being Moderated

wait function

Jul 12, 2012 8:06 AM

Tags: #breaks #pause #actionscript #stop #loop #function #wait

hi,

 

i know how to loop a function using a timer, however i can't break the loop.

 

simply im trying to achieve

 

 

something happens

wait 0.1 sec

something happens

wait 0.1 sec

....

 

and after a second the loop breaks.

 

Thanks in advance.

 
Replies
  • kglad
    62,147 posts
    Jul 21, 2002
    Currently Being Moderated
    Jul 12, 2012 8:18 AM   in reply to Lemon Video

    you can't use a for, do or while loop.  use a timer loop:

     

    var t:Timer=new Timer(100,0);

    t.addEventListener(TimerEvent.TIMER,f);

    t.start();

    function f(e:TimerEvent):void{

    // do whatever

    }

     
    |
    Mark as:
  • Currently Being Moderated
    Jul 12, 2012 8:34 AM   in reply to Lemon Video

    what are you trying to do?

     
    |
    Mark as:
  • kglad
    62,147 posts
    Jul 21, 2002
    Currently Being Moderated
    Jul 12, 2012 8:43 AM   in reply to Lemon Video

    you can use the currentCount property of your timer:

     

     

    var shakeAmplitude:int = 3;

    var t:Timer=new Timer(100,0);

    t.addEventListener(TimerEvent.TIMER,f);

    t.start();

    function f(e:TimerEvent):void{

    mc.y+=shakeAmplitude*(2*(e.target.currentCount%2)-1);

    }

     
    |
    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