3 Replies Latest reply on May 24, 2006 6:31 AM by michael novia

    removing instanced movie clips

    michael novia Level 1
      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!