Developing Flash Lite 2.x and 3.0 Applications
Create a custom text input focus manager
- Create a new document from the Flash Lite 2.0 template that you created in "Creating a Flash Lite document template" in Getting Started with Flash Lite 2.x and 3.0, and save it as custom_focus_manager.fla.
- Using the Text tool, create a text field on the Stage.
- With the text field still selected, in the Property inspector, select Input Text from the Text Type pop-up menu, type inputTxt_1 in the Instance Name text box, and select the Show Border Around Text option.
- In the same manner, create another input text field below the first one with the instance name of inputTxt_2 and select the Show Border Around Text option for the second text field.
- In the Timeline, select Frame 1 in the layer named ActionScript.
- Open the Actions panel (Window > Actions) and enter (or copy and paste) the following code:
// Disable focus rect globally:
_focusrect = false;
// Create Selection listener object:
var focusListener:Object = new Object ();
// Define onSetFocus method:
focusListener.onSetFocus = function (oldFocus, newFocus) {
// Enable/disable selection indicator:
if (newFocus instanceof TextField) {
// Set border color of text field with new focus to red:
newFocus.borderColor = 0xFF0000;
}
if (oldFocus != undefined && oldFocus instanceof TextField) {
// Set border color of text field with old focus to black:
oldFocus.borderColor = 0x000000;
}
};
// Add listener to Selection object:
Selection.addListener (focusListener);
// Set initial focus when application loads:
Selection.setFocus (inputTxt_1);
// Enable full-screen mode:
fscommand2 ("FullScreen", true);
- Save your changes and test the application in the emulator (Control > Test Movie).
- Press the emulator's down and up arrow keys to switch keypad focus between the two text fields. The text field with focus should have a red border, and the text field without focus should have a black border. Press the select key when a text field has focus to make the text input dialog box appear.