Skip to main content
commoniq_49504929
Participating Frequently
January 3, 2019
Question

How to start the script without a pause, for a Quick Time Event? Simple Question?

  • January 3, 2019
  • 2 replies
  • 557 views

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!

This topic has been closed for replies.

2 replies

Community Expert
January 3, 2019

Maybe remove the stop();

Ned Murphy
Legend
January 3, 2019

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).

commoniq_49504929
Participating Frequently
January 3, 2019

yeah, that pretty much worked. I can't believe I didn't think of that. thanks

JoãoCésar17023019
Community Expert
Community Expert
January 3, 2019

Hi.

I'm not sure of what you mean by pause in this context.

Can you explain in another way?

Regards,

JC

Colin Holgate
Inspiring
January 3, 2019

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.