I have the problem with the hitTest. The var "u" does not exist withen the moveHoriz function so the hitTest creates an error. However when I move the line "var u:UFO = new UFO();" into the main code. The hitTest works but it will not let there be more than one instance of UFO on stage at one time. Another thing I tried was add the same line of code into the moveHoriz funtion and that does let there be more than one instance on stage at one time but the hitTest does not seem to work even though there is no reported error. Any ideas?
ActionScript Code:
function shootit(){
milk.width -= 30;
var t:Laser = new Laser(); addChild(t);
t.x = cow.x, t.y = cow.y;
t.addEventListener(Event.ENTER_FRAME, moveHoriz);
}
function addufo() {
var u:UFO = new UFO(); addChild(u);
u.y = 200;
u.addEventListener(Event.ENTER_FRAME, umh);
}
function moveHoriz(e:Event):void
{
var t:MovieClip = MovieClip(e.currentTarget);
t.x -= 8;
t.y += 1;
if (t.hitTestObject(u)){t.x = 0, pwns+=1, ufomsg.text = "UFO pwns " + pwns};
if (t.x < 0)
{
t.removeEventListener(Event.ENTER_FRAME, moveHoriz);
removeChild(t);
}
}
function umh(e:Event):void
{
var u:MovieClip = MovieClip(e.currentTarget);
u.x +=4;
if (u.x > 600) {
removeChild(u);
u.removeEventListener(Event.ENTER_FRAME, umh);
}
}