Copy link to clipboard
Copied
Hi, I'm not super experienced in using animate for more than just simple animation, but I'm trying to make something for work. This project requires me to be able to change scenes by pressing a key on my keyboard. Basically, I need a scene to change to Scene1 when I press the A key, and Scene2 when I press the S key. How might a be able to make this happen? Based on some searching I've done, it seems buttons may be how I go about this, but I don't know how to make a button state change by pressing a keyboard key, or anything like that. If it helps, I'll need to export the file to a swf file when I'm all done. Thanks in advance!
Hi.
Put this code in the first frame of your first scene:
import flash.ui.Keyboard;
import flash.events.KeyboardEvent;
function keyDownHandler(e:KeyboardEvent):void
{
if (e.keyCode == Keyboard.A)
gotoAndStop(1, "Scene 1");
else if (e.keyCode == Keyboard.S)
gotoAndStop(1, "Scene 2");
}
stop();
stage.addEventListener(KeyboardEvent.KEY_DOWN, keyDownHandler);
Regards,
JC
Copy link to clipboard
Copied
Hi.
Put this code in the first frame of your first scene:
import flash.ui.Keyboard;
import flash.events.KeyboardEvent;
function keyDownHandler(e:KeyboardEvent):void
{
if (e.keyCode == Keyboard.A)
gotoAndStop(1, "Scene 1");
else if (e.keyCode == Keyboard.S)
gotoAndStop(1, "Scene 2");
}
stop();
stage.addEventListener(KeyboardEvent.KEY_DOWN, keyDownHandler);
Regards,
JC
Find more inspiration, events, and resources on the new Adobe Community
Explore Now