Copy link to clipboard
Copied
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.
and
_________________________________
stop();
button_5.addEventListener(MouseEvent.CLICK, fl_ClickToGoToNextFrame_3);
function fl_ClickToGoToNextFrame_3(event:MouseEvent):void
{
nextFrame();
}
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;
}
}
}
Hi.
This is a focus issue.
This happens when you test from within Animate CC.
Try going to your OS file explorer and run the SWF from there. The keyboard events are probably going to be fired without a previous mouse click.
You can also try to use...
stage.focus = this;
... in the main timeline to reinforce the needed focus.
Please let us know if this works.
Regards,
JC
Copy link to clipboard
Copied
Hi.
This is a focus issue.
This happens when you test from within Animate CC.
Try going to your OS file explorer and run the SWF from there. The keyboard events are probably going to be fired without a previous mouse click.
You can also try to use...
stage.focus = this;
... in the main timeline to reinforce the needed focus.
Please let us know if this works.
Regards,
JC
Copy link to clipboard
Copied
Fixed. Thank you!!
You can also try to use...
1.stage.focus = this;
... in the main timeline to reinforce the needed focus.
I added the code you suggested, and that worked perfectly. Thank you.
-------------------
Try going to your OS file explorer and run the SWF from there. The keyboard events are probably going to be fired without a previous mouse click.
I have found that simply running the file in a browser isn't the perfect solution because different browsers may or may not fire the events without a previous mouse click. So I went with the more certain fix of adding the code.