0

I' m making a game which have 2 levels, 3 scenes. After the last scenes, it will go back to the beginning at the first scenes. The problem is in the last scene, I made a loop of MCs which are targets to shoot with this code:

for(i=1;i<=numTarget;i++){
    tar=_root.attachMovie("mcTarget","t"+i,i);
    tar._x=random(Stage.width);
    tar._y=-random(Stage.height);
    tar._xscale=random(50)+50;
    tar._yscale=tar._xscale;
    tar.onEnterFrame=targetRun;
}

function targetRun(){
    this._y+=spdTarget*(this._xscale/100);
    if(this._y>Stage.height){
        this._x=random(Stage.width);
        this._y=-this._height;
    }

I found they come back again and again in that very first scene until I go to the second scene. I tried so many code and put them in so many place for all day now. What I want is to remove them after the time is up which I use the Interval code.

What I've tried, for example:

tar=delete _root.attachMovie("mcTarget","t"+i,i);
    mcTarget.swapDepths(_root.getNextHighestDepth(0));
    mcTarget.removeMovieClip();

or change a number of amount

numTarget=0;

or create a fake scene, before the real first scene. Also this code,

_root.tar.swapDepths(_root.getNextHighestDepth());
    _root.tar.removeMovieClip();

or

mcTarget._visible=false;
_root.tar._visible=false; 
tar._visible=false;

What can I do any more?

Jens Erat
  • 37,523
  • 16
  • 80
  • 96
TeeTee
  • 65
  • 2
  • 11
  • How about deleting the enterFrame and removing the clip ? `function removeTargets():Void{for(i=1;i<=numTarget;i++){delete this["t"+i].onEnterFrame; this["t"+i].removeClip();}}` – George Profenza Jan 27 '13 at 14:35
  • `code`} rePlaytxt = 365; rePlay = function(){ rePlaytxt--; if(rePlaytxt==0){ clearInterval(countBack); this.onEnterFrame=removeTarget; gotoAndPlay("intro",2); } } countBack = setInterval(rePlay,50); function removeTargets():Void{ for(i=1;i<=numTarget;i++){ delete this["t"+i].onEnterFrame; this["t"+i].removeClip(); } } `code` Where Should I put it? I tried like that but, it dosen't work too. – TeeTee Jan 27 '13 at 15:44
  • OMG!!! Thank you @George Profenza You have made it! :} I saw that kind of code but dont know how to use. And then I figure it out... may be I should put it at the place I don't want that hell MC come up! I applied yours, just doesn't have to be function(); just for.... Anyway, Thank you so much again. – TeeTee Jan 27 '13 at 16:25
  • glad you've worked it out. would be nice to document your answer so it's easier to future users encountering a similar issue. happy coding – George Profenza Jan 28 '13 at 17:36
  • That's a good idea. I will! – TeeTee Jan 31 '13 at 14:41

1 Answers1

0

Ok... As I could find the answer of how to get rid of MC(s) (Movie Clip) that I made to be loop, I'll post the answer right here. In this case there is 2 scenes so the first is the scene that has MC and another is a scene that I want to stop MC

To stop it, go to the second scene and add that for-code like you put in the #1 scene to a frame

   for(i=1;1<=numTarget;i+1){
delete this["t"+i"].onEnterFrame;
this["t"+i].removeMovieClip();
}

Please note that you have to change the code follow yours.

//using delete _root..... << that I used to do before didn't work, someone said it because this code will all delete the function and all mc that didn't manually placed on screen and stuck it at the top left of the screen :P It did happen to me too.

TeeTee
  • 65
  • 2
  • 11