Why a mouse click before my actions will work?
I've built a very simple animation
stop - immediately on the first frame
mouse click on button - go to the next frame and stop
and then I have an image that I have set to move (scroll) - Move with Keyboard Arrows
plus another button - go to previous frame and stop
That's it. Super basic.
My question is why do I have to do a mouse click before the "Move with Keyboard Arrows" action will work??
and
How do I make the "Move with Keyboard Arrows" action work without having to do a mouse click first?
_________________________________
FRAME 1
stop();
button_5.addEventListener(MouseEvent.CLICK, fl_ClickToGoToNextFrame_3);
function fl_ClickToGoToNextFrame_3(event:MouseEvent):void
{
nextFrame();
}
FRAME 2
stop();
button_3.addEventListener(MouseEvent.CLICK, fl_ClickToGoToPreviousFrame);
function fl_ClickToGoToPreviousFrame(event:MouseEvent):void
{
prevFrame();
}
var upPressed:Boolean = false;
var downPressed:Boolean = false;
var leftPressed:Boolean = false;
var rightPressed:Boolean = false;
movieClip_1.addEventListener(Event.ENTER_FRAME, fl_MoveInDirectionOfKey);
stage.addEventListener(KeyboardEvent.KEY_DOWN, fl_SetKeyPressed);
stage.addEventListener(KeyboardEvent.KEY_UP, fl_UnsetKeyPressed);
function fl_MoveInDirectionOfKey(event:Event)
{
if (upPressed)
{
movieClip_1.y -= 5;
}
if (downPressed)
{
movieClip_1.y += 5;
}
if (leftPressed)
{
movieClip_1.x -= 5;
}
if (rightPressed)
{
movieClip_1.x += 5;
}
}
function fl_SetKeyPressed(event:KeyboardEvent):void
{
switch (event.keyCode)
{
case Keyboard.UP:
{
upPressed = true;
break;
}
case Keyboard.DOWN:
{
downPressed = true;
break;
}
case Keyboard.LEFT:
{
leftPressed = true;
break;
}
case Keyboard.RIGHT:
{
rightPressed = true;
break;
}
}
}
function fl_UnsetKeyPressed(event:KeyboardEvent):void
{
switch (event.keyCode)
{
case Keyboard.UP:
{
upPressed = false;
break;
}
case Keyboard.DOWN:
{
downPressed = false;
break;
}
case Keyboard.LEFT:
{
leftPressed = false;
break;
}
case Keyboard.RIGHT:
{
rightPressed = false;
break;
}
}
}
