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 />

Create interactive objects that raise the keyboard wh<strong>en</strong> they gain focus. (Not supported by AIR applications on iOS.)<br />

(AIR only) Disable the automatic panning behavior so that your application can modify its own display to<br />

accommodate the keyboard.<br />

Controlling virtual keyboard behavior<br />

The runtime automatically op<strong>en</strong>s the virtual keyboard wh<strong>en</strong> the user taps inside a text field or a specially configured<br />

interactive object. Wh<strong>en</strong> the keyboard op<strong>en</strong>s, the runtime follows the native platform conv<strong>en</strong>tions in panning and<br />

resizing the application cont<strong>en</strong>t so that the user can see the text as they type.<br />

Wh<strong>en</strong> the keyboard op<strong>en</strong>s, the focused object dispatches the following ev<strong>en</strong>ts in sequ<strong>en</strong>ce:<br />

softKeyboardActivating ev<strong>en</strong>t — dispatched immediately before the keyboard begins to rise over the stage. If you<br />

call the prev<strong>en</strong>tDefault() method of the dispatched ev<strong>en</strong>t object, the virtual keyboard does not op<strong>en</strong>.<br />

softKeyboardActivate ev<strong>en</strong>t — dispatched after softKeyboardActivating ev<strong>en</strong>t handling has completed. Wh<strong>en</strong><br />

the focused object dispatches this ev<strong>en</strong>t, the softKeyboardRect property of the Stage object has be<strong>en</strong> updated to<br />

reflect the area of the stage obscured by the virtual keyboard. This ev<strong>en</strong>t cannot be canceled.<br />

Note: If the keyboard changes size, for example, wh<strong>en</strong> the user changes the keyboard type, the focused object dispatches a<br />

second softKeyboardActivate ev<strong>en</strong>t.<br />

softKeyboardDeactivate ev<strong>en</strong>t — dispatched wh<strong>en</strong> the virtual keyboard closes for any reason. This ev<strong>en</strong>t cannot be<br />

canceled.<br />

The following example adds two TextField objects on the stage. The upper TextField prev<strong>en</strong>ts the keyboard from<br />

raising wh<strong>en</strong> you tap the field and closes it if it is already raised. The lower TextField demonstrates the default behavior.<br />

The example reports the soft keyboard ev<strong>en</strong>ts dispatched by both text fields.<br />

package<br />

{<br />

import flash.display.Sprite;<br />

import flash.text.TextField;<br />

import flash.text.TextFieldType;<br />

import flash.ev<strong>en</strong>ts.SoftKeyboardEv<strong>en</strong>t;<br />

public class SoftKeyboardEv<strong>en</strong>tExample ext<strong>en</strong>ds Sprite<br />

{<br />

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

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

public function SoftKeyboardEv<strong>en</strong>tExample()<br />

{<br />

tf1.width = this.stage.stageWidth;<br />

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

tf1.border = true;<br />

this.addChild( tf1 );<br />

tf1.addEv<strong>en</strong>tList<strong>en</strong>er( SoftKeyboardEv<strong>en</strong>t.SOFT_KEYBOARD_ACTIVATING, prev<strong>en</strong>tSoftKe<br />

yboard );<br />

tf1.addEv<strong>en</strong>tList<strong>en</strong>er( SoftKeyboardEv<strong>en</strong>t.SOFT_KEYBOARD_ACTIVATE, prev<strong>en</strong>tSoftKe<br />

yboard );<br />

tf1.addEv<strong>en</strong>tList<strong>en</strong>er( SoftKeyboardEv<strong>en</strong>t.SOFT_KEYBOARD_DEACTIVATE, prev<strong>en</strong>tSoftKeyboard<br />

);<br />

tf2.border = true;<br />

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

Last updated 6/6/2012<br />

567

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

Saved successfully!

Ooh no, something went wrong!