KeyEvent drivin' me crazy

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

KeyEvent drivin' me crazy

niels seidel
what is the trick about listening to a key event? is there a  
different implemtation needed then in flash9?

i don't get rid of it and would be thankfull to receive some hints.
--------------------------


class Test{

public function new(){
        flash.Lib.current.addEventListener
(flash.events.KeyboardEvent.KEY_DOWN, keyDownListener);
}

public function keyDownListener(e:flash.events.KeyboardEvent){
        var b = new flash.display.MovieClip();
        b.graphics.beginFill(0xeeeeee);
        b.graphics.lineStyle(1,0x000000);
        b.graphics.drawRect(3,0,200,18);
        flash.Lib.current.addChild(b);
}

public static function main(){
        var t = new Test();
}
} // end class
--
haXe - an open source web programming language
http://haxe.org

smime.p7s (3K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: KeyEvent drivin' me crazy

Ali Jaya Meilio Lie
niels seidel wrote:

> what is the trick about listening to a key event? is there a different
> implemtation needed then in flash9?
>
> i don't get rid of it and would be thankfull to receive some hints.
> --------------------------
>
>
> class Test{
>
> public function new(){
>     flash.Lib.current.addEventListener(flash.events.KeyboardEvent.KEY_DOWN,
> keyDownListener);  
> }
>
> public function keyDownListener(e:flash.events.KeyboardEvent){
>     var b = new flash.display.MovieClip();
>     b.graphics.beginFill(0xeeeeee);
>     b.graphics.lineStyle(1,0x000000);
>     b.graphics.drawRect(3,0,200,18);
>     flash.Lib.current.addChild(b);
> }
>
> public static function main(){
>     var t = new Test();
> }
> } // end class
you should addEventListener in stage of a displayObject.

change this code:
flash.Lib.current.addEventListener(flash.events.KeyboardEvent.KEY_DOWN,
keyDownListener);

to this code:
flash.Lib.current.stage.addEventListener(flash.events.KeyboardEvent.KEY_DOWN,
keyDownListener);

hope it will help you :D

thanks,
alijaya

--
haXe - an open source web programming language
http://haxe.org