Using an input method editor

An input method editor (IME) lets users type non-ASCII text characters in Asian languages such as Chinese, Japanese, and Korean. The IME class in ActionScript lets you directly manipulate the operating system's IME in the Flash Player application that is running on a client computer.

Using ActionScript, you can determine the following:

The IME class can determine which conversion mode the current IME is using: for example, if the Japanese IME is active, you can determine if the conversion mode is Hiragana, Katakana (and so on) using the System.IME.getConversionMode() method. You can set it with the System.IME.setConversionMode() method.

NOTE

 

Curently, you cannot tell which IME is active (if any), or change from one IME to another (for instance, English to Japanese or Korean to Chinese)

You can also disable or enable the IME by using your application at runtime, and perform other functions, depending on the user's operating system. You can check whether a system has an IME by using the System.capabilities.hasIME property. The next example shows how to determine whether the user has an IME installed and active.

To determine whether the user has an IME installed and active:

  1. Create a new Flash document and save it as ime.fla.
  2. Add the following ActionScript to Frame 1 of the main Timeline:
    if (System.capabilities.hasIME) {
        if (System.IME.getEnabled()) {
            trace("You have an IME installed and enabled.");
        } else {
            trace("You have an IME installed but not enabled.");
        }
    } else {
        trace("Please install an IME and try again.");
    }
    

    The preceding code first checks whether the current system has an IME installed. If an IME is installed, Flash checks whether it is currently enabled.

  3. Select Control > Test Movie to test the document.

    A message appears in the Output panel stating whether you have an IME installed and currently active.

You can also use the IME class to enable and disable the IME in Flash at runtime. The following example requires that you have an IME installed on your system. For more information on installing an IME on your specific platform, see the following links:

You can enable and disable an IME while the SWF file plays, as shown in the following example.

To enable and disable an input method editor at runtime:

  1. Create a new Flash document and save it as ime2.fla.
  2. Create two button symbol instances on the Stage and give them the instance names enable_btn and disable_btn.
  3. Add the following ActionScript to Frame 1 of the main Timeline:
    checkIME();
    
    var my_fmt:TextFormat = new TextFormat();
    my_fmt.font = "_sans";
    
    this.createTextField("ime_txt", 10, 100, 10, 320, 240);
    ime_txt.border = true;
    ime_txt.multiline = true;
    ime_txt.setNewTextFormat(my_fmt);
    ime_txt.type = "input";
    ime_txt.wordWrap = true;
    
    enable_btn.onRelease = function() {
        System.IME.setEnabled(true);
    };
    disable_btn.onRelease = function() {
        System.IME.setEnabled(false);
    };
    
    function checkIME():Boolean {
        if (System.capabilities.hasIME) {
            if (System.IME.getEnabled()) {
                trace("You have an IME installed and enabled.");
                return true;
            } else {
                trace("You have an IME installed but not enabled.");
                return false;
            }
        } else {
            trace("Please install an IME and try again.");
            return false;
        }
    }
    

    The preceding code is separated into five sections. The first section calls the checkIME() method, which displays a message in the Output panel if the system has an IME installed or active. The second section defines a custom text-format object, which sets the font to _sans. The third section creates an input text field and applies the custom text format. The fourth section creates some event handlers for the enable_btn and disable_btn instances created in an earlier step. The fifth, and final, section of code defines the custom checkIME() function, which checks whether the current system has an IME installed and if so, whether or not the IME is active.

  4. Save the FLA file and select Control > Test Movie to test the document.

    NOTE

     

    This example requires that you have an IME installed on your system. For information on installing an IME, see the links that precede this example.

    Type some text into the input text field on the Stage. Switch your IME to a different language and type in the input text field again. Flash Player inputs characters by using the new IME. If you click the disable_btn button on the Stage, Flash reverts to using the previous language and ignores the current IME settings.

For information on System.capabilities.hasIME, see hasIME (capabilities.hasIME property) in the ActionScript 2.0 Language Reference.


Version 8

 

Send me an e-mail when comments are added to this page | Comment Report

Current page: http://livedocs.adobe.com/flash/8/main/00001482.html