Please note that as of October 24, 2014, the Nokia Developer Wiki will no longer be accepting user contributions, including new entries, edits and comments, as we begin transitioning to our new home, in the Windows Phone Development Wiki. We plan to move over the majority of the existing entries over the next few weeks. Thanks for all your past and future contributions.

Revision as of 18:34, 6 April 2008 by marty3 (Talk | contribs)

Archived:Handling keypress events in Flash Lite

From Wiki
Jump to: navigation, search

Compatibility: Flash Lite: 1.1, 2.x


Handling keypress event using the on handler

A way to handle a keypress event is using this statement:
on(keyPress aKeyCode) {A command handling code}

This example shows you how to handle "Up" and "9" keypress events:

  • Using the Text tool, drag a static text field outside your document.

Handle keyevent.jpg

  • Convert this text into a button: Select the text field -> Right click -> Convert to Symbol -> Select Button
  • Open the Actions panel and add the following code:
on(keyPress "<Up>") 
trace("You have pressed the Up key");
//Add your command handling code here
on(keyPress "9")
//Add your command handling code here

List of key constants

To handle the Soft Keys, you must first call the SetSoftKeys command.

Device button Keypress code
0-9, *, # 0-9, *, #
Left Arrow key <Left>
Right Arrow key <Right>
Up Arrow key <Up>
Down Arrow key <Down>
Select key <Enter>
Left soft key <PageUp>
Right soft key <PageDown>

Handling keypress events using a key listener (Flash Lite 2.x only)

//Create a listener object named keyListener 
var keyListener:Object = new Object();
//Define a function that responds to the KeyDown event
keyListener.onKeyDown = function()
if (Key.getCode() == Key.UP)
trace("You have pressed the Up key");
//Add your command handling code here
trace("You have pressed: "+Key.getCode());
//The keyListener object is then registered to the Key object

For handling the Soft Keys using a key listener, see Flash Lite 2.0 Soft Keys Example


You can download an example with source code here:
Handle key events.jpg
Handling keypress event using the on handler 240*320 (swf + fla)

52 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.


Thank you!

We appreciate your feedback.