Skip to main content
May 23, 2006
Question

removing instanced movie clips

  • May 23, 2006
  • 2 replies
  • 301 views
I am trying to clean up all the 'instanced' bad guys that are created during game play. Im having some problems though! I can get them to reset, but they keep coming back anyway!

this is the code i use to create them..

function initEnemy() {
for (i; i<enemys; i++) {
attachMovie("res", "enemy"+i, i*100);
//create new enemys for each loop
trace("made res");
enemy = _root["enemy"+i];
updateEnemy(enemy);
enemy.onEnterFrame = function() {
for (var j = 0; j<10; j++) {
if (this.hitTest(eval("_root.bullet"+j))) {
score += 100;
updateEnemy(this);
unloadMovie(eval("_root.bullet"+j));
enemyDie(eval("_root.bullet"+j)._x, eval("_root.bullet"+j)._y);
}
}
if (this._x>0) {
this._x -= this.velo;
} else {
updateEnemy(this);
}
};
}
}
initEnemy();
function updateEnemy(which) {
which.gotoAndStop(random(5));
which._x = random(100)+530;
which._y = random(60)+120;
which.velo = random(6)+2;
}

and this is the code i use to destroy them all:

function clearStage() {

gotoAndStop(122);
trace("trying to clean");
var enemys = 0;
for (j=0; j<100; j++) {
updateEnemy(_root["enemy"+j]);
removeMovieClip(eval("_root.bullet"+j));
//remove bullets and enemys
}
}

thanks so much!
This topic has been closed for replies.

2 replies

May 24, 2006
No, not after they have been shot, all of them need to be removed when i call the function, for things like, the end of the level, i dont want enemys still floating around in the back.

Even when i move to a new scene, they still are being created. So i need to stop them from being created, and delete all the current ones on the stage.

thanks
Inspiring
May 23, 2006
Not too sure about this one, are you saying you want to remove a bad guy instance once he has been shot?
Inspiring
May 23, 2006
in your clearStage(),

Shouldn't this: removeMovieClip(eval("_root.bullet"+j));

be this : removeMovieClip(_root["enemy"+j]);
or at least that line be added?

? just a shot in the dark really