Skip navigation
3dcruiser
Currently Being Moderated

Actionscript 2 - stop a function

Aug 2, 2012 11:27 AM

I have a function to make a number count up tp sixty. I want it so if you leave the frame the counter will reinitiate on return. As it is, the counter works fine the first time through, but runs faster everytime you return to frame. Here is the code.

 

textValue = 10;
addValue = 1;
txt_ET.text = textValue;


function countUp(){
  clearInterval(Interval);

if (textValue < 60){
clearInterval(Interval);
textValue += addValue;
txt_ET.text = textValue;
 
}

}

setInterval(countUp,800);

 
Replies
  • Currently Being Moderated
    Aug 2, 2012 12:17 PM   in reply to 3dcruiser

    Is the name of the setInterval 'Interval'? Are you actually clearing it, since setinterval's name hasn't been declared.

     
    |
    Mark as:
  • Currently Being Moderated
    Aug 2, 2012 1:11 PM   in reply to 3dcruiser

    You should look in the help documentation regarding the use of setInterval and clearInterval to learn how they work. 

     

    If you want to clear an interval you need something to identify the interval.   When the setInterval function executes, it returns a Number value that is such an identifier.  You use that number in the clearInterval function call.  So for what you show above, your setInveral line should look something like...

     

       var Interval:Number = setInterval(countUp, 800);

     

    then your clearInterval function call as shown should work... except you have a redundant calling of it within the function... one of the two shown is unnecessary - I would guess the first...

     

       function countUp(){

          clearInterval(Interval);

     

          if (textValue < 60){

               clearInterval(Interval);

     
    |
    Mark as:
  • Currently Being Moderated
    Aug 2, 2012 1:56 PM   in reply to 3dcruiser

    I don't see how setInterval works into managing a counter when you are using a frame-based design.  Changing frames should be sufficient as far as whatever your counting is dealing with.

     
    |
    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