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

Help setting up arrow key navigation from label to label.

New Here ,
Mar 30, 2013 Mar 30, 2013

I tried editing some code I was able to use to add button click navigation from label to label.

My goal was to setup backwards and forward navigation using the keyboard.

I've clearly messed something up big.

Can anyone help me fix this code???

import flash.events.KeyboardEvent;

import flash.ui.Keyboard;

stage.addEventListener(KeyboardEvent.KEY_DOWN, KeyboardHandler);

var myLabels:Array = ["intro","study_obj","exec_sum","country","submenu","us","china","germany"];

var nextLabel:String;

var inc:int = -1;

var PrevLabel:String;

stage.addEventListener(KeyboardEvent.KEY_DOWN, KeyboardHandler);

function KeyboardHandler(event:KeyboardEvent):void

{

  if(event.keyCode == 37)

{

     inc++;

    if(inc < myLabels.length){

        gotoAndPlay(String(myLabels[inc]));

    } else {

        inc = 0;  // keep it at the start  

    }

}

function KeyboardHandler(event:KeyboardEvent):void

{

  if(event.keyCode == 39)

{

{

    inc--;

    if(inc > -1 ){

         gotoAndPlay(String(myLabels[inc]));

    } else {

         inc = myLabels.length - 1; // keep it at the end 

    }

}

Sorry. I'm a newbie and having trouble.

Thank you!

TOPICS
ActionScript
606
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

LEGEND , Mar 31, 2013 Mar 31, 2013

You cannot have two functions with the same name.  So combine the code for both into one and see if that gets you any closer....

function KeyboardHandler(event:KeyboardEvent):void

{

    if(event.keyCode == 37) {

        inc++;

        if(inc < myLabels.length){

             gotoAndPlay(String(myLabels[inc]));

        } else {

             inc = 0;  // keep it at the start  

        }

    } else if(event.keyCode == 39) {

        inc--;

        if(inc > -1 ){

             gotoAndPlay(String(myLabels[inc]));

  

...
Translate
LEGEND ,
Mar 31, 2013 Mar 31, 2013

You cannot have two functions with the same name.  So combine the code for both into one and see if that gets you any closer....

function KeyboardHandler(event:KeyboardEvent):void

{

    if(event.keyCode == 37) {

        inc++;

        if(inc < myLabels.length){

             gotoAndPlay(String(myLabels[inc]));

        } else {

             inc = 0;  // keep it at the start  

        }

    } else if(event.keyCode == 39) {

        inc--;

        if(inc > -1 ){

             gotoAndPlay(String(myLabels[inc]));

        } else {

             inc = myLabels.length - 1; // keep it at the end 

        }

    }

}

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
New Here ,
Mar 31, 2013 Mar 31, 2013

AWESOME!!! Works great! Thank you!!

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
LEGEND ,
Apr 03, 2013 Apr 03, 2013
LATEST

You're welcome

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