View Full Version : keypress help
annaodonoghue
03-09-2010, 07:43 PM
Hi,
Ive been searching on the web for days....does any know if I can programme a simple keypress on a keyboard such as P to play and pause a movie or sound???
Heh, and where were you searching?... There's more tutorials and articles on this subject then you could shake a stick at...
Creating the listener:
AS2:
http://www.google.com/search?hl=en&ei=CbmWS_2tJ4u1tgeJxYnsDQ&sa=X&oi=spell&resnum=0&ct=result&cd=1&ved=0CAUQBSgA&q=key+listener+as2&spell=1
AS3:
http://www.google.com/search?hl=en&q=key+listener+as3&aq=f&aqi=&aql=&oq=
KeyCodes:
http://www.google.com/search?hl=en&q=key+codes+flash&aq=f&aqi=g1g-sx1&aql=&oq=
var keyListener:Object = new Object();
var isPlaying:Boolean = new Boolean(false);
keyListener.onKeyDown = function():Void {
if (Key.isDown(80)) {
if (!isPlaying) {
myMc.play();
isPlaying = true;
} else {
myMc.stop();
isPlaying = false;
}
}
};
Key.addListener(keyListener);
Btw, if the trouble you're having is that it's not responding to the keyPresses in the IDE, you need to be sure the swf has focus, and you must click on Control>Disable Keyboard Shortcuts or some keys will not function. (I also believe holding down shift will make it fire regardless of that setting.)
Also, this really should have been in the Simple Stuff forum, or at the very least As2/3 depending on what you were looking for. You'll get responses faster if you have your question in the right forum. This one is strictly for dealing with animation and effects. Good luck!
|
vBulletin® v3.8.5, Copyright ©2000-2012, Jelsoft Enterprises Ltd.