×
Namespaces

Variants
Actions
Revision as of 07:01, 2 February 2012 by hamishwillee (Talk | contribs)

Archived:Handling keypress events in Flash Lite

From Nokia Developer Wiki
Jump to: navigation, search

This article shows how to handle keypress events in Flash Lite using the on handler or a key listener (Flash Lite 2.x only). It also lists the key constants.

Article Metadata
Compatibility
Platform(s): Flash Lite: 1.1, 2.x
Article
Created: soueldi (29 May 2007)
Last edited: hamishwillee (02 Feb 2012)

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
}
else
{
trace("You have pressed: "+Key.getCode());
}
};
//The keyListener object is then registered to the Key object
Key.addListener(keyListener);

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

65 page views in the last 30 days.
×