Copy link to clipboard
Copied
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!
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]));
...
Copy link to clipboard
Copied
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
}
}
}
Copy link to clipboard
Copied
AWESOME!!! Works great! Thank you!!
Copy link to clipboard
Copied
You're welcome
Find more inspiration, events, and resources on the new Adobe Community
Explore Now