Well... I've noticed that you have two ENTER_FRAME events happening; moveObject and testHit, and moveObject is calling the function hitWalls every frame. I usually don't like having two separate functions for ENTER_FRAME, because whatever they're both doing can most likely be called from the same function that determines the game loop. But I see what you're trying to do here. moveObject is self-explanatory, hitTest is where you're checking for collision, and I believe hitWalls is where you're checking to see if you've hit a wall and are pushing them back from it.
Ok, so try something like this:
ActionScript Code:
import flash.display.MovieClip;
var downArrow:Boolean = false;
var speed:Number = 2;
var left:Number = 0;
var right:Number = stage.stageWidth;
var top:Number = 0;
var bottom:Number = stage.stageHeight;
var Attack:MovieClip = new MovieClip();
var isHit:Boolean = false;//TessaLee added this
stage.addEventListener(KeyboardEvent.KEY_DOWN, keyHit);
stage.addEventListener(KeyboardEvent.KEY_UP, nokeyHit);
stage.addEventListener(Event.ENTER_FRAME, movieLoop);
function keyHit (event:KeyboardEvent):void
{
switch (event.keyCode)
{
case Keyboard.DOWN :
downArrow = true;
break;
}
}
function nokeyHit(event:KeyboardEvent):void
{
switch (event.keyCode)
{
case Keyboard.DOWN :
downArrow = false;
break;
}
}
function movieLoop(event:Event)
{
if(downArrow == true)
{
objectMove.y += speed; //Moves the object
hitWalls(); //Collision Check
if(isHit == false) //Will only be true if we hit the test object
{
testHit(); //Collision Check
}
}
}
function hitWalls()
{
//Put all of your if and else if statements for the function here
}
function testHit()
{
if(objectMove.hitTestObject(objectWall))
{
isHit = true; //No longer runs this function in the movie loop
//You can also disable the entire movie loop if you don't need to control movement anymore by doing what you did before with removing the entire listener.
addChild(Attack);
}
}
I hope this helps (: