Home Tutorials Forums Articles Blogs Movies Library Employment Press
Old 04-11-2012, 03:43 AM   #1
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 //

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



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



// up //

var globalListener:Object = new Object();

globalListener.onKeyDown = function() {
if (Key.isDown(Key.UP)) {


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

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);
Noct is offline   Reply With Quote
Old 04-13-2012, 08:21 PM   #3
Registered User
Join Date: Apr 2012
Posts: 7

it worked! thanks!
lordquasi is offline   Reply With Quote

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 02:03 PM.

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.