Copy link to clipboard
Copied
Hi guys,
i'm pretty sure this is quite simple to do, but i'm very newbie in Flash yet...
I just wanna easy way to add a function integrated in my button script (in the timeline, not inside the button)
e.g.: When i press "right arrow", it'll execute the "btn_next" button ("play();")
at moment, my AS in the timeline is:
stop();
btn_next.onRelease = function(){
play()
}
btn_recu.onRelease = function(){
gotoAndStop(1)
};
i'm looking for something like:
stop();
btn_next.onRelease = function(){
if(Key.isDown(Key.RIGHT)) {
play();
}
}
btn_recu.onRelease = function(){
if(Key.isDown(Key.LEFT)) {
gotoAndStop(1)
}
};
This is obviously wrong, just an exemple!
If you want the keyboard to have the same functionality as the buttons then you need to create a listener for the keyboard and check the key pressed...
var keyListener:Object = new Object();
Key.addListener(keyListener);
keyListener.onKeyDown = function(){
trace(Key.getCode());
if(Key.getCode() == 38) trace("up");
if(Key.getCode() == 40) trace("down");
if(Key.getCode() == 37) trace("left");
if(Key.getCode() == 39) trace("right");
}
Just replace the traces with your action code
Copy link to clipboard
Copied
If you want the keyboard to have the same functionality as the buttons then you need to create a listener for the keyboard and check the key pressed...
var keyListener:Object = new Object();
Key.addListener(keyListener);
keyListener.onKeyDown = function(){
trace(Key.getCode());
if(Key.getCode() == 38) trace("up");
if(Key.getCode() == 40) trace("down");
if(Key.getCode() == 37) trace("left");
if(Key.getCode() == 39) trace("right");
}
Just replace the traces with your action code
Copy link to clipboard
Copied
Thanks Ned, it works...but there's a problem
when i advance to the next frame, and go back to the frame with this keyListener script, it goes cumulative (execute the trace functions twice)
how can i disable it after the first time?
Copy link to clipboard
Copied
Try: delete keyListener.onKeyDown;
Find more inspiration, events, and resources on the new Adobe Community
Explore Now