Sat 7 Jan 2006
Using Button
In Flash Lite 1.1, if we want to detect a key press (single press or continuous press), we need to attach the code to a button:
no += 1;
}
In Flash Lite 2, we can use back modern ActionScript, use Movie Clip or Object to do the key detection, for example:
Using Movie Clip as Key Listener
switch (Key.getCode()) {
case Key.UP :
no += 1;
break;
}
};
Key.addListener(mc);
Using Object as Key Listener
obj.onKeyDown = function() {
switch (Key.getCode()) {
case Key.UP :
no += 1;
break;
}
};
Key.addListener(obj);
However, using key listener has a side effect, you cannot detect continuous key press (press the key without release). If you want to detect continuous key press, you need to use an MovieClip.onEnterFrame:
if (Key.isDown(Key.UP)) {
no += 1;
}
};
//Key.addListener(obj);
By the way, I find the Flash Lite 2 emulator is even worse than Flash Lite 1.1 emulator because the latter one support pressing keyboard for testing (single press or continuous press), no need to use the mouse to click the phone button.
Here is the summary of the above testing:
| Continuous Pressing Detecting Method | Press without Release in Handset | Press phone button without Release | Press the key in the PC keyboard without Release | ||
| FL 1.1 Emulator | FL 2 Emulator | FL 1.1 Emulator | FL 2 Emulator | ||
| Button | Support (Slower) | Not Support | Not Support | Support | Not Support |
| Object | Not Support | N/A | Not Support | N/A | Not Support |
| Movie Clip | Not Support | N/A | Not Support | N/A | Not Support |
| Movie Clip onEnterFrame | Support (Faster) | N/A | Support | N/A | Not Support |
Download the source files

March 23rd, 2006 at 12:04 am
I wonder if an interval would work as well or better than the movieclip with onEnterFrame.
March 29th, 2006 at 7:22 pm
[...] So, I decide to take a hack on the Flash Paper 2 swf format. I know Flash Paper convert a doc based on a template swf file located at: C:Program FilesMacromediaFlashPaper 2InterfaceDefaultViewer2.swf. I use ASV 5.0 to decompile it, study the code, remove all unnecessary class files and class methods. Add further key support and the continuous key press detection I used to create a FlashPaper 2 for Flash Lite 2 version (download to that location and overwrite the file, remember backup/rename the original DefaultViewer2.swf first!) [...]
May 8th, 2006 at 10:41 pm
[...] The key handling is taken from Luar’s “Best Practice for Key Detection in Flash Lite 2″ article. The classes are my messy mostly undocumented code with help from the FL2 Dynamic Menu example. [...]
January 26th, 2008 at 6:14 pm
how to make multiplayer flash lite game that use infrared to transport data
March 15th, 2009 at 4:50 am
hey key press to page is it the same as ..keypress to button