Search code examples
flashfor-loopactionscript-2scenemc

Flash AS2: How can I delete mc that made to be loop?


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?


Solution

  • 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.