# Deleting an attached MC var?

**URL:** <https://forum.kirupa.com/t/deleting-an-attached-mc-var/218687>\
**Category:** flash\
**Created:** [March 9, 2007, 7:24pm UTC](https://forum.kirupa.com/t/deleting-an-attached-mc-var/218687 "2007-03-09T19:24:07Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Esoltas](https://avatars.discourse-cdn.com/v4/letter/e/5e9695/32.png) [@Esoltas](https://forum.kirupa.com/u/Esoltas)\
**Post date:** [March 9, 2007, 7:24pm UTC](https://forum.kirupa.com/t/deleting-an-attached-mc-var/218687/1 "2007-03-09T19:24:07Z")

</div>

I have a vertical shooter game. My problem is that the enemies (randomly duplicated with \_root.attachMovie) need to delete after being hit by bullets (" "). I stand in variables like st = something + i, with i increasing after each execution. For some reason, when I run debug, the numbers jump around (1,7,25,69,122), and I can’t adress the hitTest. Could anyone help? If you need it, I can send you the whole game and you can alter the AS. **My email is [esoltas@gmail.com](mailto:esoltas@gmail.com)**. Here’s the code:  
mouseListener = new Object();  
Mouse.addListener(mouseListener);  
function moveHero(speed) {  
//check if key is down  
if (Key.isDown(Key.LEFT)) {  
\_root.hero.\_x -= speed;  
} else if (Key.isDown(Key.RIGHT)) {  
\_root.hero.\_x += speed;  
}  
mouseListener.onMouseDown = function() {  
fireBullets();  
};  
}  
var i;  
function fireBullets() {  
i++;  
var newname = “bullet”+i;  
\_root.attachMovie(“bullet”, newname, i);  
\_root[newname].\_y = \_root.hero.\_y-100;  
\_root[newname].\_x = \_root.hero.\_x;  
\_root[newname].onEnterFrame = function() {  
var bullet\_speed = 4;  
var alpha\_decrease = 3;  
this.\_y -= bullet\_speed;  
this.\_alpha -= alpha\_decrease;  
this.\_yscale -= alpha\_decrease;  
this.\_xscale -= alpha\_decrease;  
if (this.\_y\<-22) {  
this.removeMovieClip();  
}  
};  
}  
a = 0;  
setting = 1;  
onEnterFrame = function () {  
a += 1;  
moveHero(5);  
if (random(50) == 0) {  
setting += 1;  
var enemy:MovieClip = attachMovie(“enemy”, “enemy”+a, a);  
enemy.\_x = Stage.width+enemy.\_width;  
enemy.\_y = random(145);  
enemy.gotoAndStop(setting);  
enemy.speed = (Math.random()\*10)+2;  
enemy.onEnterFrame = function() {  
this.\_x -= enemy.speed;  
if (this.\_x\<-100) {  
this.removeMovieClip();  
}  
if (setting\>10) {  
setting = 0;  
}  
};  
}  
};
