Re: [Flashcoders] Best way to detect key KEY_DOWN on MovieClip

2009-09-27 Thread Glen Pike

Hi,

You should be able to do this with something like below. You can add 
your code on the timeline, or inside a class, it's up to you. You will 
need to make sure that the thing the code is inside has been added to 
the stage - you listen for keyboard events on the stage, not the 
movieclip, so you may have to implement some code to check what is in 
focus, or otherwise...


HTH

Glen

//Import your keyboard libraries.
import flash.events.KeyboardEvent;
import flash.ui.Keyboard;

//when your movieclip or it's parent are added to stage, then use this 
to add a keyboard listener to the overall stage (not the individual 
movieclip!)

stage.addEventListener(KeyboardEvent.KEY_DOWN, onKeyDown);
stage.addEventListener(KeyboardEvent.KEY_UP, onKeyUp);

//Handle the down event (you can ignore this if you just want the 
pressrelease of a key)

function onKeyDown(event:KeyboardEvent):void
{
if(event.keyCode == Keyboard.DELETE)
{
trace(Delete key is down);
}

}
//handle the key up event...
function onKeyUp(event:KeyboardEvent):void {
if(event.keyCode == Keyboard.DELETE)
{
trace(Delete key is up);
}
}

ktt wrote:

Hello,

I would like to add listener to movieclip, listenining for DELETE. What is the 
best way to do that? In Actionscript 3 it gets complicated.

Thank you in advance,
Ktt


  
___

Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

  


--

Glen Pike
01326 218440
www.glenpike.co.uk http://www.glenpike.co.uk

___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


[Flashcoders] Best way to detect key KEY_DOWN on MovieClip

2009-09-24 Thread ktt
Hello,

I would like to add listener to movieclip, listenining for DELETE. What is the 
best way to do that? In Actionscript 3 it gets complicated.

Thank you in advance,
Ktt


  
___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders