# Problem with hitTest

**URL:** https://forum.kirupa.com/t/problem-with-hittest/307875
**Category:** Uncategorized
**Created:** [April 12, 2010, 3:59pm UTC](https://forum.kirupa.com/t/problem-with-hittest/307875 "2010-04-12T15:59:08Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![buster20](https://avatars.discourse-cdn.com/v4/letter/b/7bcc69/32.png) [@buster20](https://forum.kirupa.com/u/buster20)
#### Post date: [April 12, 2010, 3:59pm UTC](https://forum.kirupa.com/t/problem-with-hittest/307875/1 "2010-04-12T15:59:08Z")

</div>

Hi guys,

My first post here and hopefully the first of many!

The code is actionscript 2.0 using Flash version10

Basically i’m trying to make a space invaders-esqe game and having a problem or two along the way.

Here is the code for the enemy:

```auto
enemy.onEnterFrame = function() {
    //omitted movement code (not relevent);
    }
    if (enemy.hitTest(bullet)) {
        _root.enemy._alpha=20;
    }
    else _root.enemy._alpha=100;
}

```

Using this basic hitTest function just get it working, so I can build on it. When I fire the bullet it doesn’t detect any hit at all. I can’t work out what is wrong!

The following code is for the firing of the bullet:

```auto
gunEmplacement.onEnterFrame = function() {

    //omitted movement code (not relevent);

    if(Key.isDown(40)){
        _root.attachMovie('bullet', 'bullet'+bulletNum,+1,1);
        _root['bullet'+bulletNum]._x = gunEmplacement._x + gunEmplacement._width/2 - _root['bullet'+bulletNum]._width/2;
        _root['bullet'+bulletNum]._y = gunEmplacement._y;
        _root['bullet'+bulletNum].onEnterFrame = function(){
            
            this._y -= 8; 
            
            if(this._y < 0 * this._height){
                
                this.removeMovieClip();
        }
    }
}

```

That is the code for how many bullet gets generated and is the one that is meant to hit the enemy ship. What is wrong with the code I have wrote and why won’t it recognise a hit? Is it because of the attachmovie?
