# \[FLASH8\]Firing bullets from a rotating spaceship

**URL:** <https://forum.kirupa.com/t/flash8-firing-bullets-from-a-rotating-spaceship/218353>\
**Category:** flash\
**Created:** [March 7, 2007, 1:25am UTC](https://forum.kirupa.com/t/flash8-firing-bullets-from-a-rotating-spaceship/218353 "2007-03-07T01:25:14Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dragonist](https://avatars.discourse-cdn.com/v4/letter/d/54ee81/32.png) [@Dragonist](https://forum.kirupa.com/u/Dragonist)\
**Post date:** [March 7, 2007, 1:25am UTC](https://forum.kirupa.com/t/flash8-firing-bullets-from-a-rotating-spaceship/218353/1 "2007-03-07T01:25:14Z")

</div>

Hey, all!

I’m making an asteroids-esque type game and need to make it so when you press the spacebar bullets come out from the tip of the spaceship. Can someone please explain to me why this code doesn’t work? Another thing-syntax was correct last time I checked.

```auto
keyListener = new Object();
Key.addListener(keyListener);
keylistener.onKeyDown = function() {
    if (Key.isDown(Key.SPACE)) {
    shipFire();
    }
};
var i;
function shipFire() {
    i++;
    var newname = "bullet"+i;
    var bulletSpeed = 20;
    _root.attachMovie("bullet", newname, i);
    _root[newname]._x = _root.total._x;
    _root[newname]._y = _root.total._y;
    _root[newname].onEnterFrame = function() {
        this._x += bulletSpeed*Math.sin(player._rotation*(Math.PI/180));
        this._y -= bulletSpeed*Math.cos(player._rotation*(Math.PI/180));
    };
};

```

PS- This is the part of the code where I have the firing function  
The problem is the _**if(Key.isDown(Key.SPACE)) {**_ part of the code. I know this because I did this:

```auto
keyListener = new Object();
Key.addListener(keyListener);
keylistener.onKeyDown = function() {
    if (Key.isDown(Key.SPACE)) {
    shipFire();
    trace ("commencing shipFire");
    }
};

```

and nothing was traced when I pressed the spacebar. Did I do something stupid (which is often the problem for me) or is there a bigger problem? One more thing-- I know this has been done billions of times in those more-than-common rotating turret & tank games so if you have the .fla for one of those maybe you could compare mine with yours.

Thank you!!:thumb2:

–Dragonist
