Copy link to clipboard
Copied
For a Quick Time Event or any code, I think...
For some reason, the first keyboard event starts off with a pause. How do I let this script starts off without it having to be pressed the first time? I already wrote the instructions for the player about how it works.
import flash.events.KeyboardEvent;
import flash.ui.Keyboard;
function keyDownHandler(e:KeyboardEvent):void
{
if (currentScene.name == "Scene 1")
{
if (e.keyCode == Keyboard.E)
nextScene();
}
else if (currentScene.name == "Scene 2")
{
if (e.keyCode == Keyboard.F)
nextScene();
}
else if (currentScene.name == "Scene 3")
{
if (e.keyCode == Keyboard.G)
nextScene();
}
}
stop();
if (!stage.hasEventListener(KeyboardEvent.KEY_DOWN))
stage.addEventListener(KeyboardEvent.KEY_DOWN, keyDownHandler);
Image example (start button not included in the above code)
respect points on the line!
Copy link to clipboard
Copied
Hi.
I'm not sure of what you mean by pause in this context.
Can you explain in another way?
Regards,
JC
Copy link to clipboard
Copied
I think that the issue is that in a browser you can't read the key_down event until after a user action has put the stage into focus. If that is the case it's a security related issue. Without requiring a user action it would be possible to have a SWF hidden on the web page, that watches what keys the user is pressing.
I didn't answer already because the start button ought to be enough to count as a user action. It would be useful to see the test FLA.
Copy link to clipboard
Copied
I got it now. I just remove the stop command thing.
Because when the script or whatever you guys call it reaches the frame, the first key you have to press never moves forward until it has been pressed.
One question at a time.
I realise there's more to this
Copy link to clipboard
Copied
Maybe remove the stop();
Copy link to clipboard
Copied
stop(); is a timeline command, not a code processing command - tells the 'playhead' to stop in that frame. It executes pretty much as soon as you enter the frame, long before any keyboard interaction is encountered (relatively speaking).
Copy link to clipboard
Copied
yeah, that pretty much worked. I can't believe I didn't think of that. thanks
Find more inspiration, events, and resources on the new Adobe Community
Explore Now