A Flash Developer Resource Site

Results 1 to 7 of 7

Thread: help needed with clearInterval on multiple mc's

  1. #1
    Senior Member mandissected's Avatar
    Join Date
    Jan 2005
    Location
    Berwick - England
    Posts
    338

    help needed with clearInterval on multiple mc's

    I'm using setInterval and clearInterval for setting and resetting (on reload) of speeds. This works fine when I have a single mc but when I have multiple mc's I can't seem to get the clearInterval to work.

    Can anyone help me?

  2. #2
    Senior Member
    Join Date
    Aug 2000
    Location
    Montréal
    Posts
    14,141
    post your code and give more info on your setup.

    gparis

  3. #3
    Senior Member mandissected's Avatar
    Join Date
    Jan 2005
    Location
    Berwick - England
    Posts
    338
    OK, this is what I have -

    Code:
    //at start of frame
    clearInterval(rockmove);
    
    
    //function in the frame
    function startrocks() {
    	rocksarray = new Array();
    	rocknumber = 0;
    	for (i=0; i<4; i++){
    		rockmc = newrock(100);
    		rockmc._x = 500*Math.random();
    		rockmc._y = 500*Math.random();
    	}
    }
    
    
    function newrock(scale){
    	rocknumber++ ;
                 rockmc = attachMovie("rock", "rock" + rocknumber, rocknumber);
    	rockmc._xscale = scale;
    	rockmc._yscale = scale;
    	rockmc.dx = (4*(Math.random()-0.5));
    	rockmc.dy = (4*(Math.random()-0.5));
    	rockmove = setInterval(moverock, 50, rockmc)
    	//store in array
    	rocksarray.push(rockmc);
    	//reset rockmc
    	return rockmc;
    }
    I've got a similar set up for my ship which works fine, the only difference is that the rocks are multiple mc's running of the same code. I'm guessing this will reset one rocks setInterval but not them all.

    Anyone have a solution?

    Someone else has suggested I us onEnterFrame instead, would that be easier? I have no experience with using it though.

    Thanks for any help guys.

  4. #4
    Senior Member Dricciotti's Avatar
    Join Date
    Aug 2002
    Posts
    2,988
    You dont have to use onEnterFrame. What I am seeing as a possible problem is when you use setInterval() you are setting "rockmove" as the controller ID for the interval. Using the same name for all of them may be leading to problems. I would try storing in an array the ID's of the interval as well and accessing them like that. Then, to clear them just pop off the one you want to clear or all of them (depending on what you want to do)
    Code:
    function newrock(scale){
    	rocknumber++ ;
                 rockmc = attachMovie("rock", "rock" + rocknumber, rocknumber);
    	rockmc._xscale = scale;
    	rockmc._yscale = scale;
    	rockmc.dx = (4*(Math.random()-0.5));
    	rockmc.dy = (4*(Math.random()-0.5));
    	rockIDarray.push(setInterval(moverock, 50, rockmc));
    	//store in array
    	rocksarray.push(rockmc);
    	//reset rockmc
    	return rockmc;
    }
    ***note*** That line in bold is only a suggestion and I havent even checked it to see if it works.
    Post back with progess and I hope that helps

  5. #5
    Senior Member mandissected's Avatar
    Join Date
    Jan 2005
    Location
    Berwick - England
    Posts
    338
    Works perfect, thanks Driciotti! thants relieved me of one haeadache, just a few more to solve and I'll have a game ready for release!

  6. #6
    Senior Member Dricciotti's Avatar
    Join Date
    Aug 2002
    Posts
    2,988
    glad to hear it helped. Drop a link when your done

  7. #7
    Senior Member mandissected's Avatar
    Join Date
    Jan 2005
    Location
    Berwick - England
    Posts
    338
    I have a beta version at http://www.mandissected.co.uk/spacerocks.htm if you're interested. You'll have to forgive it being pretty basic, it's only my second game. Any feedback would be great.

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