Name

Selection Object — control over text field selections

Availability

Flash 5

Synopsis

Selection.methodName( )

Methods

getBeginIndex( )

Retrieve the index of the first selected character.

getCaretIndex( )

Retrieve the index of the insertion point.

getEndIndex( )

Retrieve the index of the last selected character.

getFocus( )

Identify the text field in which the insertion point currently resides.

setFocus( )

Place the insertion point in a specific text field.

setSelection( )

Select characters in the currently focused text field.

Description

We use the Selection object to control user interaction with text fields and to capture portions of text fields. In actual use, the Selection object methods are preceded by the keyword Selection; they always operate on the text field with focus, of which there can be only one at any given time. The methods of a Selection object can position the insertion point and can select or retrieve a text field’s content. These abilities add subtle but important behavior to user-input systems. For example, in a user-login screen, we can prompt a user to enter his name by placing the cursor in a name-entry text field. Or we can highlight an error in a form by selecting the problematic text. We can also customize the so-called Tab order of a series of text fields, as shown under Selection.setFocus( ) Method.

Positions of the characters in a text field are referred to with zero-relative indexes where the first character is index 0, the second is index 1, and so on. ...

Get ActionScript: The Definitive Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.