Copy link to clipboard
Copied
Hi, I have been this ActionScript a lot -
var keyListener:Object = new Object();
Key.addListener(keyListener);
function keyDownF(){
play();
}
keyListener.onKeyDown = keyDownF;
But would like to know how to revise it so I could isolate the specific keys I do or don't want to be used.
Also is it possible to disable so it only works at a particular part in my time line? If I use it now it will work on every frame.
Any advice would be helpful.
Thanks again
Jason
Hi Jason, here is a simplified bit of code that works based on specific keys. You would just replace the "trace()" commands with your intended actions...
var keyListener:Object = new Object();
Key.addListener(keyListener);
keyListener.onKeyDown = function(){
// trace(Key.getCode()); // use this trace to determine other key codes
if(Key.getCode() == 38) trace("up");
if(Key.getCode() == 40) trace("down");
if(Key.getCode() == 37) trace("left");
if(Key.getCode() == 39) trace("right");
}
A
...Copy link to clipboard
Copied
Hi Jason, here is a simplified bit of code that works based on specific keys. You would just replace the "trace()" commands with your intended actions...
var keyListener:Object = new Object();
Key.addListener(keyListener);
keyListener.onKeyDown = function(){
// trace(Key.getCode()); // use this trace to determine other key codes
if(Key.getCode() == 38) trace("up");
if(Key.getCode() == 40) trace("down");
if(Key.getCode() == 37) trace("left");
if(Key.getCode() == 39) trace("right");
}
As far as only allowing this to function in specific frames, you could utilize other conditionals that check if the _currentframe property is a value that allows for it. You could also assign the Key.onKeyDown to be null when you do not want it to be active.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now