A Flash Developer Resource Site

Results 1 to 8 of 8

Thread: ClearInterval that was set inside a movieclip?

  1. #1
    Junior Member
    Join Date
    May 2008
    Posts
    8

    Question ClearInterval that was set inside a movieclip?

    I have a movieclip where I have lots of code, because its kind of a module. Inside it have have some AS2 code inside a movieclip called "mymodule"
    Code:
    var myinterval;
    
    some_movieclip.onRelease = function(){
    	clearInterval(myinterval);
    	myinterval = setInterval(myfunction, 200);
    };
    However, when I go to another "section" in my Flash, I need to make sure all intervals are cleared, because a user could easily click on another section while something is running and it needs to clear them.

    But I cant figure out how to kill intervals I have set.

    The following doesn't work of course
    Code:
    mymodule.clearInterval(myinterval);
    And this dont work either
    Code:
    clearInterval(mymodule["myinterval"]);
    Any ideas? Thanks in advance
    Last edited by pers0n; 04-28-2009 at 12:52 AM.

  2. #2
    Junior Member
    Join Date
    Aug 2002
    Posts
    3

    hello

    I have the same problem. Did you get to figure out an answer?

    -Doug

  3. #3
    Junior Member
    Join Date
    May 2008
    Posts
    8
    i found some code to clear all intervals.

    http://board.flashkit.com/board/showthread.php?t=392425

    Also another alternative I just now thought of is to define a interval and a function to clear it on the main timeline instead of in the movieclip. Then inside the movieclip you should be able to do the onrelease and call that function on the timeline to clear it.

  4. #4
    Member
    Join Date
    Apr 2009
    Posts
    41

    interval not clearing up..

    I have definite set of 5functions namely rb1(),rb2(),rb3(),rb4() and rb5().
    Each has to be played one after another in a sequence after 5,10,15,20,30s such they seems like movie.
    I call them via setInterval() in a loop.
    for (m=0; m<6; m++)
    {
    set("_root.id"+(m), (setInterval(eval("_root.play"+(m)), timep)));
    var container:Number=timeMonitor(m);
    timep = timep+container;
    }

    where by timeMonitor() I take different value of time.
    function timeMonitor(step):Number
    {
    if(step==1)
    {
    time=5000;
    }
    else if(step==2)
    {
    time=10000;
    }
    else if(step==3)
    {
    time=15000;
    }
    else if(step==4)
    {
    time=20000;
    }
    else if(step==5)
    {
    time=30000;
    }
    return time;
    }

    I have also cleared up Interval in each rb1(),rb2(),rb3(),rb4() and rb5(). as clearInterval(_root.id1);clearInterval(_root.id2) etc
    When I execute my code, then for first time it execute as desired. Then for second round as game refreshes by function which I defined then it execute abnormally seems chaos and repitation.All id are also initialize in beginning.
    Any help how it can be corrected ???

    Thanks.

  5. #5
    Junior Member
    Join Date
    May 2008
    Posts
    8
    One thing I can tell you right away is that flash will not hit the time 5000, 10000, 15000, ... perfectly, it will probably be off by some miliseconds.

    I would probably have a 5 second interval at the end of each function - rb1(), rb2(), ... - rather than the way you have it right now. But be sure to clear the previous one before it runs and also clear itself before doing the interval.

  6. #6
    Member
    Join Date
    Apr 2009
    Posts
    41
    thanks..
    No matter if it goes up/down by milliseconds or more...

    Kindly suggest how it would be look like?
    Do you want setInterval() to called in rb1() itself??
    function rb2()
    {
    clearInterval(_root.id1);
    clearInterval(_root.id2);
    ----------->
    setInterval(rb3,timep);
    }

    Is this the way you are suggesting ?

  7. #7
    Senior Member
    Join Date
    Nov 2004
    Posts
    928
    person
    if you have a movieClip (mc1) inside which is another movieClip (mc2) inside which is an interval (myinterval) then the way to stop the interval is
    clearInterval(mc1.mc2.myinterval)

  8. #8
    Senior Member
    Join Date
    Nov 2004
    Posts
    928
    ransi
    does this help as an idea?

    function r1() {
    trace("r1");
    clearInterval(int1);
    int2 = setInterval(r2,5000);
    }
    function r2() {
    trace("r2");
    clearInterval(int2);
    int3 = setInterval(r3,5000);
    }
    function r3() {
    trace("r3");
    clearInterval(int3);
    int1 = setInterval(r1,5000);
    }
    int1 = setInterval(r1,5000);

Tags for this Thread

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