A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: clearInterval : Reset Clear all variables

  1. #1
    Senior Member
    Join Date
    Jun 2001
    Posts
    250

    clearInterval : Reset Clear all variables

    Hello,

    The setInterval works fine. So does the clearInterval. However, I'm trying to create a RESET button that simply reloads the swf (to restate my movie from the beginning). What happens is that the movie never really clears any variable like getTimer etc. The new movie retains all the old values/varibles. Even if I reset all variables to 0 or null, the newly reloaded movie retains the previous values it had before closing.

    How do I truly clear all variables using clearInterval?

    Thanks in advance.

    iastini

    mypause = setInterval(ftimer,1);

    btn1.onPress = function(){//stop
    clearInterval(mypause);
    }

    btn2.onPress = function(){//quit
    fscommand("Quit");
    }

    btn3.onPress = function(){//reset
    clearInterval(mypause);
    mypause2 = setInterval(ftimer,1);
    loadMovie("timer_motivate.swf", "_level0");

    }

  2. #2
    http://pat.theorigin.net cresquin's Avatar
    Join Date
    Jun 2003
    Location
    Los Angeles, CA
    Posts
    685
    The easiest way to do this is to create an array that keeps track of all of the setintervals you create. Then make a function that runs through the array and clears them all.

  3. #3
    http://pat.theorigin.net cresquin's Avatar
    Join Date
    Jun 2003
    Location
    Los Angeles, CA
    Posts
    685
    Sorry, I totally missed this one. ClearInterval will ONLY clear a timer. If you want to reset your variables, you need to expressly set them to a new value.

    In your script above, it looks like clearInterval is being used out of scope in reference to mypause. that line should read:

    clearinterval(_root.mypause);

    then in that same function you create a new timer mypause2. It will be rather impossible to clear mypause2 because you are declaring the variable reference within the function. Declaring a variable means that only that function has access to it. You should declare the variable outside the function:

    var mypause2;

    then you can use it within a function and have access to it in other functions as well.

  4. #4
    Senior Member
    Join Date
    Jun 2001
    Posts
    250
    Thanks guys, this sounds like a plan.

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