Help with Key Listeners  
Author Message
CDogg79





PostPosted: 2006-7-12 0:37:43 Top

flash-actionscript, Help with Key Listeners First I'd like to say thank you to anyone that can help me out with this.

I've set up a key listner and it works fine with the space bar but I want to
use the number keys to control it instead. Numbers 1, 2, 3 and 4 to be exact
and I was wondering how I would need to change my code to have it listen for
those numbers.

Here is my code so far:

this.onEnterFrame=function()
{
if(Key.isDown(Key.SPACE))
{
One_Buzzed_In._visible = true;
buzzed = new Sound(this);
buzzed.attachSound("buzzer");
buzzed.start(0, 1);
}
}

Thanks again for any help.

 
chrebel





PostPosted: 2006-7-12 0:42:00 Top

flash-actionscript >> Help with Key Listeners you need to use the getAscii function for the Key class

var myListener:Object = new Object();
myListener.onKeyDown = function () {
if( Key.getAscii() == 49)
{
trace( "you pressed the 1" );
}
}

Key.addListener(myListener);

 
mxc





PostPosted: 2006-7-12 0:44:00 Top

flash-actionscript >> Help with Key Listeners Use getcode() to find the values of the keys you want to use then just put it
in the function. To use get code you can for example write.

var keyListener:Object = new Object();
keyListener.onKeyDown = function() {
trace("For the last key typed:");
trace("\tThe Key code is: "+Key.getCode());
};
Key.addListener(keyListener);

regards
Michael

 
 
CDogg79





PostPosted: 2006-7-12 1:04:00 Top

flash-actionscript >> Help with Key Listeners Thanks for the help guys I appreciate it and I've finally got it to work.