Package | flash.text |
Class | public final class StageText |
Inheritance | StageText EventDispatcher Object |
Language Version: | ActionScript 3.0 |
Runtime Versions: | AIR 3 |
This class enables mobile applications to gather user input using native text input controls on mobile devices. Input controls on mobile devices often have extensive user interfaces and supporting behaviors that don't exist on the desktop. For example, many mobile devices support text input features like the following:
- auto-complete
- auto-correct
- touch-based text selection
- customizable soft keyboards
The underlying operating system (or a component library bundled with the operating system) draws native text input fields. Native text input fields provide an experience that is familiar to anyone who has used other applications on the same device. However, because the operating system draws the text input fields instead of the player, you cannot use embedded fonts.
AIR profile support: This feature is fully supported on iOS and Android platforms. StageText uses native text input fields on Android and iOS mobile devices. On other platforms, StageText uses the Flash Runtime TextField.
When native inputs are used, StageText objects are not display objects
and you cannot add them to the Flash display list. Instead, you display a
StageText object by attaching it directly to a stage using the stage
property. The StageText instance attached to a stage is displayed on top of
any Flash display objects. You control the size and position of the rendering
area with the viewPort
property. There is no way to control
depth ordering of different StageText objects. Overlapping two instances
is not recommended.
When a StageText object has focus, it has the first opportunity to handle keyboard input. The stage to which the StageText object is attached does not dispatch any keyboard input events.
Because the StageText class wraps a different native control on every platform, its features are supported to varying degrees by each platform. Where features are supported, they may behave differently between platforms. When you attempt to use a particular feature on a particular platform, it is best to test the behavior. Only on desktop platforms where native controls are not used is StageText behavior similar to Flash Runtime text behavior.
Learn more
Property | Defined By | ||
---|---|---|---|
autoCapitalize : String
Controls how a device applies auto capitalization to user input. | StageText | ||
autoCorrect : Boolean
Indicates whether a device auto-corrects user input for spelling or
punctuation mistakes. | StageText | ||
color : uint
Specifies text color. | StageText | ||
constructor : Object
A reference to the class object or constructor function for a given object instance. | Object | ||
displayAsPassword : Boolean
Indicates whether the text field is a password text field. | StageText | ||
editable : Boolean
Indicates whether the user can edit the text field. | StageText | ||
fontFamily : String
Indicates the name of the current font family. | StageText | ||
fontPosture : String
Specifies the font posture, using constants defined in the FontPosture class. | StageText | ||
fontSize : int
The size in pixels for the current font family. | StageText | ||
fontWeight : String
Specifies the font weight, using constants defined in the FontWeight class. | StageText | ||
locale : String
Indicates the locale of the text. | StageText | ||
maxChars : int
Indicates the maximum number of characters that a user can enter into the text field. | StageText | ||
multiline : Boolean [read-only]
Indicates whether the StageText object can display more than one line of
text. | StageText | ||
prototype : Object [static]
A reference to the prototype object of a class or function object. | Object | ||
restrict : String
Restricts the set of characters that a user can enter into the text field. | StageText | ||
returnKeyLabel : String
Indicates the label on the Return key for devices that feature a soft keyboard. | StageText | ||
selectionActiveIndex : int [read-only]
The zero-based character index value of the first character in the current selection. | StageText | ||
selectionAnchorIndex : int [read-only]
The zero-based character index value of the last character in the current selection. | StageText | ||
softKeyboardType : String
Controls the appearance of the soft keyboard. | StageText | ||
stage : Stage
The stage on which this StageText object is displayed. | StageText | ||
text : String
The current text in the text field. | StageText | ||
textAlign : String
Indicates the paragraph alignment. | StageText | ||
viewPort : Rectangle
The area on the stage in which the StageText object is displayed. | StageText | ||
visible : Boolean
Indicates whether the StageText object is visible. | StageText |
Method | Defined By | ||
---|---|---|---|
Creates a StageText object. | StageText | ||
addEventListener(type:String, listener:Function, useCapture:Boolean = false, priority:int = 0, useWeakReference:Boolean = false):void
Registers an event listener object with an EventDispatcher object so that the listener
receives notification of an event. | EventDispatcher | ||
Assigns focus to the StageText object. | StageText | ||
Dispatches an event into the event flow. | EventDispatcher | ||
Disposes of the StageText object. | StageText | ||
Draws the StageText's view port to a bitmap. | StageText | ||
Checks whether the EventDispatcher object has any listeners registered for a specific type
of event. | EventDispatcher | ||
Indicates whether an object has a specified property defined. | Object | ||
Indicates whether an instance of the Object class is in the prototype chain of the object specified
as the parameter. | Object | ||
Indicates whether the specified property exists and is enumerable. | Object | ||
Removes a listener from the EventDispatcher object. | EventDispatcher | ||
Selects the text specified by the index values of the first and last characters. | StageText | ||
Sets the availability of a dynamic property for loop operations. | Object | ||
Returns the string representation of this object, formatted according to locale-specific conventions. | Object | ||
Returns the string representation of the specified object. | Object | ||
Returns the primitive value of the specified object. | Object | ||
Checks whether an event listener is registered with this EventDispatcher object or any of
its ancestors for the specified event type. | EventDispatcher |
Event | Summary | Defined By | ||
---|---|---|---|---|
[broadcast event] Dispatched when the Flash Player or AIR application gains operating system focus and becomes active. | EventDispatcher | |||
Dispatched after text content changes. | StageText | |||
Dispatched after setting a non-null stage and non-empty viewPort. | StageText | |||
[broadcast event] Dispatched when the Flash Player or AIR application operating loses system focus and is becoming inactive. | EventDispatcher | |||
Dispatched when the user is editing text, and the control has keyboard focus. | StageText | |||
Dispatched when the user is no longer editing text, and the control no longer has keyboard focus. | StageText | |||
Dispatched when the user presses a key. | StageText | |||
Dispatched when the user releases a key. | StageText | |||
Dispatched after the soft keyboard is activated, as a result of the StageText object acquiring focus. | StageText | |||
Dispatched before soft keyboard activation, as a result of the StageText object acquiring focus. | StageText | |||
Dispatched after the soft keyboard is deactivated, as a result of the StageText object losing focus. | StageText |
autoCapitalize | property |
autoCapitalize:String
Language Version: | ActionScript 3.0 |
Runtime Versions: | AIR 3 |
Controls how a device applies auto capitalization to user input. Valid values are defined as constants in the AutoCapitalize class:
- "none"
- "word"
- "sentence"
- "all"
The default value is AutoCapitalize.NONE.
Implementation
public function get autoCapitalize():String
public function set autoCapitalize(value:String):void
Throws
ArgumentError — If set to any value which is not a member of AutoCapitalize
|
Related API Elements
autoCorrect | property |
autoCorrect:Boolean
Language Version: | ActionScript 3.0 |
Runtime Versions: | AIR 3 |
Indicates whether a device auto-corrects user input for spelling or punctuation mistakes.
The default value is false.
Implementation
public function get autoCorrect():Boolean
public function set autoCorrect(value:Boolean):void
color | property |
color:uint
Language Version: | ActionScript 3.0 |
Runtime Versions: | AIR 3 |
Specifies text color. You specify text color as a number containing three 8-bit RGB components.
The first component represents red, the second represents green, and the third component represents blue.
For example, 0xFF0000
specifies red, 0x00FF00
specifies green, and
0x0000FF
specifies blue. The default text color is black (0x000000
).
The default value is 0x000000.
Implementation
public function get color():uint
public function set color(value:uint):void
displayAsPassword | property |
displayAsPassword:Boolean
Language Version: | ActionScript 3.0 |
Runtime Versions: | AIR 3 |
Indicates whether the text field is a password text field. If true
,
the text field hides input characters using a substitute character (for example, an
asterisk).
Important: On iOS, a multiline stage text object does not display substitute
characters even when the value of this property is true
.
The default value is false.
Implementation
public function get displayAsPassword():Boolean
public function set displayAsPassword(value:Boolean):void
editable | property |
fontFamily | property |
fontFamily:String
Language Version: | ActionScript 3.0 |
Runtime Versions: | AIR 3 |
Indicates the name of the current font family. A value of
null indicates the system default. To enumerate the available
fonts, use flash.text.Font.enumerateFonts()
. If the
font family is unknown, the default font family is used.
The default value is null.
Implementation
public function get fontFamily():String
public function set fontFamily(value:String):void
fontPosture | property |
fontPosture:String
Language Version: | ActionScript 3.0 |
Runtime Versions: | AIR 3 |
Specifies the font posture, using constants defined in the FontPosture class.
The default value is FontPosture.NORMAL.
Implementation
public function get fontPosture():String
public function set fontPosture(value:String):void
Throws
ArgumentError — If set to any value which is not a member of FontPosture
|
Related API Elements
fontSize | property |
fontWeight | property |
fontWeight:String
Language Version: | ActionScript 3.0 |
Runtime Versions: | AIR 3 |
Specifies the font weight, using constants defined in the FontWeight class.
The default value is FontWeight.NORMAL.
Implementation
public function get fontWeight():String
public function set fontWeight(value:String):void
Throws
ArgumentError — If set to any value which is not a member of FontWeight
|
Related API Elements
locale | property |
locale:String
Language Version: | ActionScript 3.0 |
Runtime Versions: | AIR 3 |
Indicates the locale of the text. StageText uses the standard locale identifiers. For example "en", "en_US" and "en-US" are all English; "ja" is Japanese. See iso639-2 code list for a list of locale codes.
The default value is en.
Implementation
public function get locale():String
public function set locale(value:String):void
maxChars | property |
maxChars:int
Language Version: | ActionScript 3.0 |
Runtime Versions: | AIR 3 |
Indicates the maximum number of characters that a user can enter into the text field.
A script can insert more text than maxChars
allows. If maxChars
equals zero, a user can enter an unlimited amount of text into the text field.
The default value is 0.
Implementation
public function get maxChars():int
public function set maxChars(value:int):void
multiline | property |
multiline:Boolean
[read-only] Language Version: | ActionScript 3.0 |
Runtime Versions: | AIR 3 |
Indicates whether the StageText object can display more than one line of
text. Read-only. This value matches that of the multiline
property in the StageTextInitOptions object used during construction.
Implementation
public function get multiline():Boolean
Related API Elements
restrict | property |
restrict:String
Language Version: | ActionScript 3.0 |
Runtime Versions: | AIR 3 |
Restricts the set of characters that a user can enter into the text field.
The system scans the restrict
string from left to right.
The value of restrict
specifies the following text input restriction rules:
- If the value is
null
, a user can enter any character. - If the value is an empty string, a user cannot enter any characters.
- If the value is a string of characters, a user can enter only the characters in the string.
- If the value includes a caret (^), a user cannot enter any characters that follow the caret.
- The value can specify a range of allowable input characters by using the hyphen (-) character.
- The value can use the
\u
escape sequence to construct arestrict
string.
Special Characters:
Use a backslash to enter a caret (^) or dash (-) character verbatim. The accepted backslash sequences are \-, \^ and \\. The backslash must be an actual character in the string. When you specify a backslash in ActionScript, use a double backslash.
Examples of restrict
property settings:
The following example allows a user to enter only the dash (-) and caret (^) characters:
my_txt.restrict = "\\-\\^";
The following example allows a user to enter only uppercase characters, spaces, and numbers:
my_txt.restrict = "A-Z 0-9";
The following example excludes only lowercase letters:
my_txt.restrict = "^a-z";
The following example allows a user to enter only uppercase letters, but excludes the uppercase letter Q:
my_txt.restrict = "A-Z^Q";
The following example allows a user to enter only the characters from ASCII 32 (space) to ASCII 126 (tilde).
my_txt.restrict = "\u0020-\u007E";
Note: Restrictions apply only to user input; a script can insert any characters into the text field.
The default value is null.
Implementation
public function get restrict():String
public function set restrict(value:String):void
returnKeyLabel | property |
returnKeyLabel:String
Language Version: | ActionScript 3.0 |
Runtime Versions: | AIR 3 |
Indicates the label on the Return key for devices that feature a soft keyboard.
The available values are constants defined in the ReturnKeyLabel
class:
- "default"
- "done"
- "go"
- "next"
- "search"
This property is only a hint to the underlying platform, because not all devices and operating systems support these values. This property has no affect on devices that do not feature a soft keyboard.
The default value is ReturnKeyLabel.DEFAULT.
Implementation
public function get returnKeyLabel():String
public function set returnKeyLabel(value:String):void
Throws
ArgumentError — If set to any value which is not a member of ReturnKeyLabel
|
Related API Elements
selectionActiveIndex | property |
selectionActiveIndex:int
[read-only] Language Version: | ActionScript 3.0 |
Runtime Versions: | AIR 3 |
The zero-based character index value of the first character in the current selection. For example, the first character is 0, the second character is 1, and so on.
Implementation
public function get selectionActiveIndex():int
Related API Elements
selectionAnchorIndex | property |
selectionAnchorIndex:int
[read-only] Language Version: | ActionScript 3.0 |
Runtime Versions: | AIR 3 |
The zero-based character index value of the last character in the current selection. For example, the first character is 0, the second character is 1, and so on.
Implementation
public function get selectionAnchorIndex():int
Related API Elements
softKeyboardType | property |
softKeyboardType:String
Language Version: | ActionScript 3.0 |
Runtime Versions: | AIR 3 |
Controls the appearance of the soft keyboard.
Devices with soft keyboards can customize the keyboard's buttons
to match the type of input expected. For example, if numeric
input is expected, a device can use SoftKeyboardType.NUMBER
to
display only numbers on the soft keyboard.
Valid values are defined as constants in the SoftKeyboardType class:
- "default"
- "punctuation"
- "url"
- "number"
- "contact"
- "email"
These values serve as hints, to help a device display the best keyboard for the current operation.
The default value is SoftKeyboardType.DEFAULT.
Implementation
public function get softKeyboardType():String
public function set softKeyboardType(value:String):void
Throws
ArgumentError — If set to any value which is not a member of SoftKeyboardType
|
Related API Elements
stage | property |
text | property |
text:String
Language Version: | ActionScript 3.0 |
Runtime Versions: | AIR 3 |
The current text in the text field. The carriage return character
('\r'
, ASCII 13) separates lines of text.
Text contained in this property is unformatted (it has no
formatting tags).
The default value is null.
Implementation
public function get text():String
public function set text(value:String):void
textAlign | property |
textAlign:String
Language Version: | ActionScript 3.0 |
Runtime Versions: | AIR 3 |
Indicates the paragraph alignment. Valid values are defined as constants in the TextFormatAlign class:
- "left"
- "center"
- "right"
- "justify"
- "start"
- "end"
Not all platforms support every textAlign
value.
For unsupported textAlign
values, platforms use
the default value (TextFormatAlign.START
).
The default value is TextFormatAlign.START.
Implementation
public function get textAlign():String
public function set textAlign(value:String):void
Throws
ArgumentError — If set to any value which is not a member of TextFormatAlign
|
Related API Elements
viewPort | property |
viewPort:Rectangle
Language Version: | ActionScript 3.0 |
Runtime Versions: | AIR 3 |
The area on the stage in which the StageText object is displayed. The default is the zero rect.
Implementation
public function get viewPort():Rectangle
public function set viewPort(value:Rectangle):void
Throws
RangeError — The Rectangle value is not valid.
|
visible | property |
StageText | () | Constructor |
public function StageText(initOptions:flash.text:StageTextInitOptions = null)
Language Version: | ActionScript 3.0 |
Runtime Versions: | AIR 3 |
Creates a StageText object.
The StageText object is invisible until it is attached to a stage and until the viewPort
property is set.
initOptions:flash.text:StageTextInitOptions (default = null )
|
assignFocus | () | method |
public function assignFocus():void
Language Version: | ActionScript 3.0 |
Runtime Versions: | AIR 3 |
Assigns focus to the StageText object. For non-editable objects,
assignFocus()
does nothing.
dispose | () | method |
public function dispose():void
Language Version: | ActionScript 3.0 |
Runtime Versions: | AIR 3 |
Disposes of the StageText object.
Calling dispose()
is optional. If you do not maintain a reference to this
StageText instance, it is eligible for garbage collection. Calling dispose()
can make garbage collection occur sooner, or occur at a more convenient time.
drawViewPortToBitmapData | () | method |
public function drawViewPortToBitmapData(bitmap:BitmapData):void
Language Version: | ActionScript 3.0 |
Runtime Versions: | AIR 3.0 |
Draws the StageText's view port to a bitmap.
Capture the bitmap and set the stage to null
to
display the content above the StageText object.
If you call this method before the Event.COMPLETE
event, the method could draw the
view port incorrectly.
Parameters
bitmap:BitmapData — The BitmapData object on which to draw the visible portion of the StageText's view port.
|
Throws
ArgumentError — The bitmap's width or height is different from view port's width or height.
| |
Error — The bitmap is null.
|
selectRange | () | method |
public function selectRange(anchorIndex:int, activeIndex:int):void
Language Version: | ActionScript 3.0 |
Runtime Versions: | AIR 3 |
Selects the text specified by the index values of the first and last characters.
You specify the first and last characters of the selection in the
anchorIndex
and activeIndex
parameters. If both parameter
values are the same, this method sets the insertion point.
On iOS, for non-multiline StageText objects, this function is not supported and does nothing.
For some devices or operating systems, the selection is only visible when the StageText object has focus.
Parameters
anchorIndex:int — The zero-based index value of the first character in the selection
(the first character's index value is 0).
| |
activeIndex:int — The zero-based index value of the last character in the selection.
|
Related API Elements
change | Event |
flash.events.Event
Language Version: | ActionScript 3.0 |
Runtime Versions: | AIR 3 |
Dispatched after text content changes. This event can be dispatched on every change, or not until a set of changes is completed.
complete | Event |
flash.events.Event
property Event.type =
flash.events.Event.COMPLETE
Language Version: | ActionScript 3.0 |
Runtime Versions: | AIR 3 |
Dispatched after setting a non-null stage and non-empty viewPort. Indicates
that the implementation has finished laying out the StageText object, and
you can now call the drawViewPortToBitmapData
method.
Depending upon the platform, this event could be dispatched synchronously or
asynchronously with the setting of the stage
, viewPort
, or both.
Event.COMPLETE
constant defines the value of the type
property of a complete
event object.
This event has the following properties:
Property | Value |
---|---|
bubbles | false |
cancelable | false ; there is no default behavior to cancel. |
currentTarget | The object that is actively processing the Event object with an event listener. |
target | The network object that has completed loading. |
focusIn | Event |
flash.events.FocusEvent
Language Version: | ActionScript 3.0 |
Runtime Versions: | AIR 3 |
Dispatched when the user is editing text, and the control has keyboard focus.
focusOut | Event |
flash.events.FocusEvent
Language Version: | ActionScript 3.0 |
Runtime Versions: | AIR 3 |
Dispatched when the user is no longer editing text, and the control no longer has keyboard focus.
keyDown | Event |
flash.events.KeyboardEvent
property KeyboardEvent.type =
flash.events.KeyboardEvent.KEY_DOWN
Language Version: | ActionScript 3.0 |
Runtime Versions: | AIR 3, Flash Lite 4 |
Dispatched when the user presses a key.
Mappings between keys and specific characters vary by device and operating system. This event type is generated after such a mapping occurs but before the processing of an input method editor (IME). IMEs are useful for entering characters that the standard QWERTY keyboard is ill-equipped to produce (for example, Chinese ideographs).
This event occurs before the keyUp
event.
This event is not dispatched for all keys. The keys that cause this event to be dispatched vary by platform.
In AIR, canceling this event prevents the character from being entered into a text field.
TheKeyboardEvent.KEY_DOWN
constant defines the value of the type
property of a keyDown
event object.
This event has the following properties:
Property | Value |
---|---|
bubbles | true |
cancelable | true in AIR, false in Flash Player;
in AIR, canceling this event prevents the character from being entered into a text field. |
charCode | The character code value of the key pressed or released. |
commandKey | true on Mac if the Command key is active. Otherwise, false |
controlKey | true on Windows and Linux if the Ctrl key is active. true on Mac if either the Control key is active. Otherwise, false |
ctrlKey | true on Windows and Linux if the Ctrl key is active. true on Mac if either the Ctrl key or the Command key is active. Otherwise, false . |
currentTarget | The object that is actively processing the Event object with an event listener. |
keyCode | The key code value of the key pressed or released. |
keyLocation | The location of the key on the keyboard. |
shiftKey | true if the Shift key is active; false if it is inactive. |
target | The InteractiveObject instance with focus.
The target is not always the object in the display list
that registered the event listener. Use the currentTarget
property to access the object in the display list that is currently processing the event. |
keyUp | Event |
flash.events.KeyboardEvent
property KeyboardEvent.type =
flash.events.KeyboardEvent.KEY_UP
Language Version: | ActionScript 3.0 |
Runtime Versions: | AIR 3, Flash Lite 4 |
Dispatched when the user releases a key.
Mappings between keys and specific characters vary by device and operating system. This event type is generated after such a mapping occurs but before the processing of an input method editor (IME). IMEs are used to enter characters that the standard QWERTY keyboard is ill-equipped to produce (for example, Chinese ideographs).
This event occurs after a keyDown
event.
This event is not dispatched for all keys. The keys that cause this event to be dispatched vary by platform.
TheKeyboardEvent.KEY_UP
constant defines the value of the type
property of a keyUp
event object.
This event has the following properties:
Property | Value |
---|---|
bubbles | true |
cancelable | false ; there is no default behavior to cancel. |
charCode | Contains the character code value of the key pressed or released. |
commandKey | true on Mac if the Command key is active. Otherwise, false |
controlKey | true on Windows and Linux if the Ctrl key is active. true on Mac if either the Control key is active. Otherwise, false |
ctrlKey | true on Windows if the Ctrl key is active. true on Mac if either the Ctrl key or the Command key is active. Otherwise, false . |
currentTarget | The object that is actively processing the Event object with an event listener. |
keyCode | The key code value of the key pressed or released. |
keyLocation | The location of the key on the keyboard. |
shiftKey | true if the Shift key is active; false if it is inactive. |
target | The InteractiveObject instance with focus.
The target is not always the object in the display list
that registered the event listener. Use the currentTarget
property to access the object in the display list that is currently processing the event. |
softKeyboardActivate | Event |
flash.events.SoftKeyboardEvent
Language Version: | ActionScript 3.0 |
Runtime Versions: | AIR 3 |
Dispatched after the soft keyboard is activated, as a result of the StageText object acquiring focus.
softKeyboardActivating | Event |
flash.events.SoftKeyboardEvent
Language Version: | ActionScript 3.0 |
Runtime Versions: | AIR 3 |
Dispatched before soft keyboard activation, as a result of the StageText object acquiring focus.
softKeyboardDeactivate | Event |
flash.events.SoftKeyboardEvent
Language Version: | ActionScript 3.0 |
Runtime Versions: | AIR 3 |
Dispatched after the soft keyboard is deactivated, as a result of the StageText object losing focus.
Mon Nov 28 2011, 06:48 AM -08:00