flash - Actionscript 3.0: Cannot get key input -
guys. created little game. nothing happening thought, because im not getting keyboard input. spend time trying create own taht didnt work. copy/pasted code official actionscript 3.0 reference page, tweaked game (but didnt touch related keyboard stuff). thing game returns in cosnole false
import flash.ui.keyboard; import flash.events.event; import flash.events.keyboardevent; stop(); var left = false; var right = false; var speed = 0.3; player.addeventlistener(keyboardevent.key_down, keydf); player.addeventlistener(keyboardevent.key_up, keyuf); player.addeventlistener(event.enter_frame, updf); function keydf(event:keyboardevent):void { trace("test0"); if(event.keycode == keyboard.d) { trace("test1"); left = true; } if(event.keycode == keyboard.a) { right = true; } } function keyuf(event:keyboardevent):void { trace("test2"); if(event.keycode == keyboard.d) { left = false; } if(event.keycode == keyboard.a) { right = false; } } function updf(e:event):void { if(left) { level.x -= speed; } if(right) { level.x += speed; } trace(left + ""); //always false :\ }
if want key input app, should add listeners stage :)
Comments
Post a Comment