13.08.2012 Views

ACTIONSCRIPT 3 Developer’s Guide en

ACTIONSCRIPT 3 Developer’s Guide en

ACTIONSCRIPT 3 Developer’s Guide en

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

<strong>ACTIONSCRIPT</strong> 3.0 DEVELOPER’S GUIDE<br />

Keyboard input<br />

var phoneTxt:TextField = new TextField();<br />

var nameTxt:TextField = new TextField();<br />

phoneTxt.type = TextFieldType.INPUT;<br />

phoneTxt.addEv<strong>en</strong>tList<strong>en</strong>er(FocusEv<strong>en</strong>t.FOCUS_IN, focusInHandler);<br />

phoneTxt.addEv<strong>en</strong>tList<strong>en</strong>er(FocusEv<strong>en</strong>t.FOCUS_OUT, focusOutHandler);<br />

phoneTxt.restrict = "0-9";<br />

phoneTxt.width = 100;<br />

phoneTxt.height = 18;<br />

phoneTxt.background = true;<br />

phoneTxt.border = true;<br />

addChild(phoneTxt);<br />

nameField.type = TextFieldType.INPUT;<br />

nameField.x = 120;<br />

nameField.width = 100;<br />

nameField.height = 18;<br />

nameField.background = true;<br />

nameField.border = true;<br />

addChild(nameField);<br />

function focusInHandler(ev<strong>en</strong>t:FocusEv<strong>en</strong>t):void<br />

{<br />

if (Capabilities.hasIME)<br />

{<br />

IME.<strong>en</strong>abled = false;<br />

}<br />

}<br />

function focusOutHandler(ev<strong>en</strong>t:FocusEv<strong>en</strong>t):void<br />

{<br />

if (Capabilities.hasIME)<br />

{<br />

IME.<strong>en</strong>abled = true;<br />

}<br />

}<br />

This example creates two input text fields, phoneTxt and nameTxt, and th<strong>en</strong> adds two ev<strong>en</strong>t list<strong>en</strong>ers to the phoneTxt<br />

text field. Wh<strong>en</strong> the user sets focus to the phoneTxt text field, a FocusEv<strong>en</strong>t.FOCUS_IN ev<strong>en</strong>t is dispatched and the<br />

IME is disabled. Wh<strong>en</strong> the phoneTxt text field loses focus, the FocusEv<strong>en</strong>t.FOCUS_OUT ev<strong>en</strong>t is dispatched to re<strong>en</strong>able<br />

the IME.<br />

List<strong>en</strong>ing for IME composition ev<strong>en</strong>ts<br />

Flash Player 9 and later, Adobe AIR 1.0 and later<br />

IME composition ev<strong>en</strong>ts are dispatched wh<strong>en</strong> a composition string is being set. For example, if the user has their IME<br />

<strong>en</strong>abled and active and types a string in Japanese, the IMEEv<strong>en</strong>t.IME_COMPOSITION ev<strong>en</strong>t would dispatch as soon as<br />

the user selects the composition string. In order to list<strong>en</strong> for the IMEEv<strong>en</strong>t.IME_COMPOSITION ev<strong>en</strong>t, you need to add<br />

an ev<strong>en</strong>t list<strong>en</strong>er to the static ime property in the System class<br />

(flash.system.System.ime.addEv<strong>en</strong>tList<strong>en</strong>er(...)), as shown in the following example:<br />

Last updated 6/6/2012<br />

565

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!