This is, I think, what you were looking for. That should be enough.
left_btn.addEventListener(MouseEvent.MOUSE_DOWN, moveLeft);
left_btn.addEventListener(MouseEvent.MOUSE_UP, LeftUp);
function moveLeft(e:MouseEvent):void
{
leftPressed = true;
left_btn.addEventListener(MouseEvent.MOUSE_OUT, LeftOut);
}
function leftUp(e:MouseEvent):void
{
leftPressed = false;
left_btn.removeEventListener(MouseEvent.MOUSE_OUT, LeftOut);
}
function leftOut(e:MouseEvent):void
{
leftPressed = false;
left_btn.removeEventListener(MouseEvent.MOUSE_OUT, LeftOut);
}
MOUSE_OUT simply trigger when the mouse is out of your Object so you only have to add an EventListener with this type of Event. Of course, you may understand that it's not that smart to listen to this event if you didn't clicked on your btn before, that's why I choose to add the MOUSE_OUT only when MOUSE_DOWN is listened. Since what you want is only to set leftPressed when you Up your mouse I guess that you want the same for when your mouse is out. After this, I remove useless listeners (MOUSE_OUT) to be able to listen to them again and because it's a common waste of memory.
But, I really can't understand why you do :
function moveLeft(e:MouseEvent):void
{
if(MouseEvent.MOUSE_DOWN){
leftPressed = true;
}else if (MouseEvent.MOUSE_UP) {
leftPressed = false;
}
}
What is the use of that ?!