Forum Moderators: open

Message Too Old, No Replies

[AS] Control MC created by attachMovie

         

Seachmall

5:19 pm on Feb 10, 2008 (gmt 0)

10+ Year Member



function fire_bullet() {
>>>> //b++;
>>>> _root.attachMovie('bullet_mc','bullet'+b+'_mc',b);
>>>> _root['bullet'+b+'_mc']._x = ship_mc._x+(ship_mc._width/2);
>>>> _root['bullet'+b+'_mc']._y = ship_mc._y+(ship_mc._height/2);

>>>> _root['bullet'+b+'_mc'].onEnterFrame = function() {
>>>>>>>> trace(b);
>>>>>>>> _root['bullet'+b+'_mc']._y -= 30;//_root.bullet_mc.speed;
>>>>>>>> if (_root['bullet'+b+'_mc']._y<0) {
>>>>>>>> removeMovieClip(_root['bullet'+b+'_mc']);
>>>>>>>> }
>>>> }
}

In order to allow for the function to check the bullet_mcs created b must not increment but in order to allow for multiple bullet_mcs at a time it must. If I include the increment the function runs forever but if not no more than one bullet_mc can exist. Any ideas on how to get around this? Do I need an array?

daperson0

10:49 pm on Feb 16, 2008 (gmt 0)

10+ Year Member



b = 0;
function fire_bullet() {
b++
var bullet = _root.attachMovie("bullet_mc","bullet"+b+"_mc",_root.getNextHighestDepth());
bullet._x = ship_mc._x+(ship_mc._width/2);
bullet._y = ship_mc._y+(ship_mc._height/2);
bullet.onEnterFrame = function() {
this._y -= 30;
if(this._y < 0) {
this.removeMovieClip();
}
}
}

Try that.