PDA

View Full Version : Detecting right and left keypresses reliably - How?


Pumpkin
03-04-2009, 10:28 AM
Hey everybody -

I'm trying to create (very) basic interactivity in Flash Lite 2.0.
Basically what I want to do is move an image around the screen using the directional buttons (up, down, left, right). So I took the code from (yet again!) Adobe's Learning Actionscript 2.0 and tried to get it running in Device Central. But the strangest thing happens - in a lot of the simulated phones, only up and down work! Only Sharp, Toshiba, and Nokia seem to get it right. I'm pretty sure the problem is the Key identifiers. Has anybody heard of this?

The code is as follows:

var distance:Number = 10;

this.createTextField("display_txt", 999, 0, 0, 100, 20);

var keyListener:Object = new Object();
keyListener.onKeyDown = function() {
if (Key.isDown(Key.LEFT)) {
car_mc._x = Math.max(car_mc._x - distance, 0);
display_txt.text = "Left";
};
if (Key.isDown(Key.RIGHT)) {
car_mc._x = Math.min(car_mc._x + distance, Stage.width - car_mc._width);
display_txt.text = "Right";
};
if (Key.isDown(Key.UP)) {
car_mc._y = Math.max(car_mc._y - distance, 0);
display_txt.text = "Up";
};
if (Key.isDown(Key.DOWN)) {
car_mc._y = Math.min(car_mc._y + distance, Stage.height - car_mc._height);
display_txt.text = "Down";
};
};
Key.addListener(keyListener);

I'm thinking that people have to do it with some kind of a hack; otherwise right and left buttons are just undetectable on like, half of all mobile phones in Japan (and quite a few in the US as well).