Highlighted

Is it possible to create a Quick Time Event game?

Explorer ,
Jan 01, 2019

Copy link to clipboard

Copied

The title pretty much says it.

I am trying to make a Quick Time Event system in which the player has to press a certain key to move on. I already know it is possible with a mouse.

If possible, how can you let a key command in actions to only work in an individual scene? I have recently discovered when you press on an assigned key (E) correctly, it would go to the next but pressing or holding on the same key while it's on a different scene will cycle through the scenes. When I assign (F) to the next attack, both E and F would cycle through them. This leaves me to believe that the code I copied somewhere didn't have a command to stop it when it reaches the next scene. Extra notes - "a next scene command" was not added, it's just a go-to command assigned to the last frame of the scene. If you like, add something better besides gotoAndPlay(98);

Using the same Character is also a problem because for some reason it goes back to the layer I first assigned to.

My intention is

I want only a single key to work for each scene, is there a way to stop the script once the duration of the scene was reached? I also want the keys to be reusable later on.

Oh yeah, and also I want the assigned key to be no longer pressable when my animated timer runs out.

Thanks: by an inexperienced scripter

Please, give me your suggestions.

Scene 1

stage.addEventListener(KeyboardEvent.KEY_DOWN, KeyPressed);

function KeyPressed(evt:KeyboardEvent):void {

    if (evt.keyCode==Keyboard.E){

       gotoAndPlay(98);

    }

}

Scene 2

stage.addEventListener(KeyboardEvent.KEY_DOWN, KeyPress);

function KeyPress(evt:KeyboardEvent):void {

    if (evt.keyCode==Keyboard.F){

       gotoAndPlay(71);

    }

}

Image Problem Example

QTE1-HELP!.jpg

no seriously...

Adobe Community Professional
Correct answer by JoãoCésar | Adobe Community Professional

Hi.

You don't need to add an event listener to the stage in each scene. Just add one in the beginning and create some conditionals. Like this:

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

I hope this helps.

Regards,

JC

Views

223

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

Is it possible to create a Quick Time Event game?

Explorer ,
Jan 01, 2019

Copy link to clipboard

Copied

The title pretty much says it.

I am trying to make a Quick Time Event system in which the player has to press a certain key to move on. I already know it is possible with a mouse.

If possible, how can you let a key command in actions to only work in an individual scene? I have recently discovered when you press on an assigned key (E) correctly, it would go to the next but pressing or holding on the same key while it's on a different scene will cycle through the scenes. When I assign (F) to the next attack, both E and F would cycle through them. This leaves me to believe that the code I copied somewhere didn't have a command to stop it when it reaches the next scene. Extra notes - "a next scene command" was not added, it's just a go-to command assigned to the last frame of the scene. If you like, add something better besides gotoAndPlay(98);

Using the same Character is also a problem because for some reason it goes back to the layer I first assigned to.

My intention is

I want only a single key to work for each scene, is there a way to stop the script once the duration of the scene was reached? I also want the keys to be reusable later on.

Oh yeah, and also I want the assigned key to be no longer pressable when my animated timer runs out.

Thanks: by an inexperienced scripter

Please, give me your suggestions.

Scene 1

stage.addEventListener(KeyboardEvent.KEY_DOWN, KeyPressed);

function KeyPressed(evt:KeyboardEvent):void {

    if (evt.keyCode==Keyboard.E){

       gotoAndPlay(98);

    }

}

Scene 2

stage.addEventListener(KeyboardEvent.KEY_DOWN, KeyPress);

function KeyPress(evt:KeyboardEvent):void {

    if (evt.keyCode==Keyboard.F){

       gotoAndPlay(71);

    }

}

Image Problem Example

QTE1-HELP!.jpg

no seriously...

Adobe Community Professional
Correct answer by JoãoCésar | Adobe Community Professional

Hi.

You don't need to add an event listener to the stage in each scene. Just add one in the beginning and create some conditionals. Like this:

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

I hope this helps.

Regards,

JC

Views

224

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Jan 01, 2019 0
Adobe Community Professional ,
Jan 02, 2019

Copy link to clipboard

Copied

So your actual question is: "Is it possible to remove keyboard event listeners?"

Yes. Yes it is.

EventDispatcher - Adobe ActionScript® 3 (AS3 ) API Reference

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jan 02, 2019 0
Adobe Community Professional ,
Jan 02, 2019

Copy link to clipboard

Copied

Hi.

You don't need to add an event listener to the stage in each scene. Just add one in the beginning and create some conditionals. Like this:

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

I hope this helps.

Regards,

JC

__________________________________________
HTML5, JSFL, and AS3 samples: http://bit.ly/2mJgDoG

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jan 02, 2019 2
Explorer ,
Jan 02, 2019

Copy link to clipboard

Copied

Wow, THANK YOU!!

Didn't expect a quick reply, but you certainly delivered!

I have been searching for the answer everywhere but can't seem to find the answer.

thanks again, have a nice day!

Happy New Year bud

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jan 02, 2019 0
Explorer ,
Jan 02, 2019

Copy link to clipboard

Copied

Wow, THANK YOU!!

Didn't expect a quick reply, but you certainly delivered!

I have been searching for the answer everywhere but can't seem to find the answer.

thanks again, have a nice day!

Happy New Year bud 🙂

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jan 02, 2019 1
Adobe Community Professional ,
Jan 02, 2019

Copy link to clipboard

Copied

Excellent! You're welcome!

__________________________________________
HTML5, JSFL, and AS3 samples: http://bit.ly/2mJgDoG

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jan 02, 2019 0