Hi
Can any one tell me the actionscript 2 code to reconize a squence of key presses to trigger next frame or next scene.
thanx in advance
Ben
ps im try to learn action script 2
Hi
Can any one tell me the actionscript 2 code to reconize a squence of key presses to trigger next frame or next scene.
thanx in advance
Ben
ps im try to learn action script 2
stop();
var keyListener:Object = new Object();
keyListener.onKeyDown = function() {
if (Key.isDown(Key.SPACE) && Key.isDown(Key.UP)) {
nextFrame();
}
};
Key.addListener(keyListener);
I need some info on this action script 2 language so I can work out how to use this code.
Because I only know the basics soz lol language isnt my strong point but i would like to try master it. thanx again
[quote=glosrfc;2346533] ActionScript Code:
[COLOR=#0000FF]stop[/COLOR]COLOR=#000000[/COLOR];
[COLOR=#000000]var[/COLOR] keyListener:[COLOR=#0000FF]Object[/COLOR] = [COLOR=#000000]new[/COLOR] [COLOR=#0000FF]Object[/COLOR]COLOR=#000000[/COLOR];
keyListener.[COLOR=#0000FF]onKeyDown[/COLOR] = [COLOR=#000000]function[/COLOR]COLOR=#000000[/COLOR] [COLOR=#000000]{[/COLOR]
[COLOR=#0000FF]if[/COLOR] [COLOR=#000000]([/COLOR][COLOR=#0000FF]Key[/COLOR].[COLOR=#0000FF]isDown[/COLOR]COLOR=#000000[/COLOR] && [COLOR=#0000FF]Key[/COLOR].[COLOR=#0000FF]isDown[/COLOR]COLOR=#000000[/COLOR][COLOR=#000000])[/COLOR] [COLOR=#000000]{[/COLOR]
[COLOR=#0000FF]nextFrame[/COLOR]COLOR=#000000[/COLOR];
[COLOR=#000000]}[/COLOR]
[COLOR=#000000]}[/COLOR];
[COLOR=#0000FF]Key[/COLOR].[COLOR=#0000FF]addListener[/COLOR]COLOR=#000000[/COLOR]; [/quote]
Info can be found by checking the keywords in the Flash help manual:
keylistener
onkeydown
key.isdown
addlistener
nextframe
Thanx for your help glosrfc.
I will master the action script language!!!
That’s the spirit…keep with it.
Sorry to bother you again you know in your example you have told it to look at the keyboard for the user to press space and up together. I want to use numbers in my “code” I look on the help menu of flash and found the key codes / ASCII key codes but I can find a example on how to use them. Also in your example you have to press them down at the same time is there a way of press one after an other.
Thanx again Ben
[quote=glosrfc;2346533] ActionScript Code:
[LEFT][COLOR=#0000FF]stop[/COLOR]COLOR=#000000[/COLOR];
[COLOR=#000000]var[/COLOR] keyListener:[COLOR=#0000FF]Object[/COLOR] = [COLOR=#000000]new[/COLOR] [COLOR=#0000FF]Object[/COLOR]COLOR=#000000[/COLOR];
keyListener.[COLOR=#0000FF]onKeyDown[/COLOR] = [COLOR=#000000]function[/COLOR]COLOR=#000000[/COLOR] [COLOR=#000000]{[/COLOR]
[COLOR=#0000FF]if[/COLOR] [COLOR=#000000]([/COLOR][COLOR=#0000FF]Key[/COLOR].[COLOR=#0000FF]isDown[/COLOR]COLOR=#000000[/COLOR] && [COLOR=#0000FF]Key[/COLOR].[COLOR=#0000FF]isDown[/COLOR]COLOR=#000000[/COLOR][COLOR=#000000])[/COLOR] [COLOR=#000000]{[/COLOR]
[COLOR=#0000FF]nextFrame[/COLOR]COLOR=#000000[/COLOR];
[COLOR=#000000]}[/COLOR]
[COLOR=#000000]}[/COLOR];
[COLOR=#0000FF]Key[/COLOR].[COLOR=#0000FF]addListener[/COLOR]COLOR=#000000[/COLOR];
[/LEFT]
[/quote]
Substitute the if statement with if (Key.isDown(53) && Key.isDown(55)) { where 53 is the key code for 5 and 55 is the key code for 7. Change the numbers to reflect the numbers you want to use.
If you want to avoid holding them down at the same time, then you can assign the key codes to a variable and check against that. For example:
var moveForward:String = “57”;
var captureKeys:String = “”;
stop();
var keyListener:Object = new Object();
keyListener.onKeyDown = function() {
if (Key.isDown(53)) {
captureKeys = captureKeys+“5”;
}
if (Key.isDown(55)) {
captureKeys = captureKeys+“7”;
}
if (captureKeys == moveForward) {
nextFrame();
}
};
Key.addListener(keyListener);
:: Copyright KIRUPA 2024 //--