Home Tutorials Forums Articles Blogs Movies Library Employment Press
Old 04-11-2012, 03:43 AM   #1
lordquasi
Registered User
 
Join Date: Apr 2012
Posts: 7
Unhappy [AS2] timeline navigation via keyboard events

I'm working on the content for a series of arcade games and I would like the player to be able to jump to a desired frame by pressing the keys "t,space, or up) I've been looking around and I'm having a lot of trouble trying to get it to work. This is my code so far.


// quick play buttons //

// t //
Key.addListener(keyListener);

keyListener = new Object();
keyListener.onKeyDown = function() {
trace(+ Key.getAscii(114) +
String.fromCharCode(Key.getAscii(t))
+ Key.getCode(84));

gotoAndPlay("whale_instructions");

}

// space //
keyListener2 = new Object();
keyListener2.onKeyDown = function() {
trace(+ Key.getAscii(32) +
String.fromCharCode(Key.getAscii(space))
+ Key.getCode(32));

gotoAndPlay("pig_out");


};



// up //
Key.addListener(keyListener);


var globalListener:Object = new Object();


globalListener.onKeyDown = function() {
if (Key.isDown(Key.UP)) {
gotoAndPlay("circle_instructions");
}


}

Key.addListener(globalListener);
lordquasi is offline   Reply With Quote
Old 04-11-2012, 05:04 PM   #2
Noct
Toys in the Attic...
 
Noct's Avatar
 
Join Date: Oct 2006
Location: NY
Posts: 3,022
Default

Welcome aboard.

You don't need a listener for each key, just one can watch the entire k/b. Also, I would target a clip with your gotoAndPlays; it's not a great practice to just leave them hanging like that, especially when they are in an object listener and not scoped directly to a clip.

Try something like this:
ActionScript Code:
var keyListener:Object = new Object(); keyListener.onKeyDown = function():Void  {     switch (Key.getCode()) {         case (37) :             //Left             trace("LEFT ARROW");             myMainMc.gotoAndPlay("whale_instructions");             break;         case (38) :             //Up             trace("UP ARROW");             myMainMc.gotoAndPlay("circle_instructions");             break;         case (39) :             //Right             trace("RIGHT ARROW");             break;         case (40) :             //Down             trace("DOWN ARROW");             break;         case (32) :             //Spacebar             trace("Space Bar");             break;     } }; Key.addListener(keyListener);
__________________
http://rwithers.com
Noct is offline   Reply With Quote
Old 04-13-2012, 08:21 PM   #3
lordquasi
Registered User
 
Join Date: Apr 2012
Posts: 7
Default

it worked! thanks!
lordquasi is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 08:26 AM.

///
Follow actionscriptorg on Twitter

 


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.