Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Change Scene by pressing a keyboard key?

New Here ,
Dec 07, 2017 Dec 07, 2017

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!

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

correct answers 1 Correct answer

Community Expert , Dec 07, 2017 Dec 07, 2017

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

Translate
Community Expert ,
Dec 07, 2017 Dec 07, 2017
LATEST

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

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