Developing Flash Lite 2.x and 3.0 Applications

Create a custom text input focus manager

  1. 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.
  2. Using the Text tool, create a text field on the Stage.
  3. 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.
  4. 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.
  5. In the Timeline, select Frame 1 in the layer named ActionScript.
  6. 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);
    
    
  7. Save your changes and test the application in the emulator (Control > Test Movie).
  8. 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.