in black and white
Main menu
Share a book About us Home
Biology Business Chemistry Computers Culture Economics Fiction Games Guide History Management Mathematical Medicine Mental Fitnes Physics Psychology Scince Sport Technics

macromedia flash mx - Reinhardt R.

Reinhardt R., Lott J macromedia flash mx - John Wiley & Sons, 2004. - 987 p.
ISBN 0-7645-4354-7
Download (direct link): macromediaflash2004.pdf
Previous << 1 .. 201 202 203 204 205 206 < 207 > 208 209 210 211 212 213 .. 419 >> Next

Working with Focus
Focus is a term used in many scripting languages to describe which part of the application is active. For example, with Web browser windows, the foreground window is usually the focused one, meaning that actions such as keyboard input are received by that window, and not another. The same thing applies to Flash applications. A Button, MovieClip, or TextField object can receive focus within Flash. For example, when a user uses the mouse to click within a TextField instance, she brings focus to that instance. Once the object has focus, the user can enter text.
436 Part V ¶ The Movie Classes
Setting Focus
The setFocus() method brings the focus to the object specified as the parameter. The parameter should be the path (relative or absolute) as a string to a MovieClip, Button, or TextField object. If the object to which you are bringing focus is a TextField object then Flash will also display the I-beam cursor within that instance.
The following example creates a new TextField object and brings focus to it:
this.createTextField("tUsername", this.getNextHighestDepth(), 25, 25, 150, 20); tUsername.border = true; tUsername.type = "input";
Listening for Focus Changes
You can add listener objects to the Selection class to be notified when focus changes occur. To add a listener object, use the Selection.addListener() method. For example, the following registers a new listener named oListener:
And to remove a listener, use the Selection.removeListener() method:
When focus changes occur, the Selection class notifies all registered listeners and calls their onSetFocus() method. The onSetFocus() method is automatically passed two parameters ó a reference to the object that previously had focus and the object that has just received focus. The following is an example:
var oFocusListener:Object = new Object();
oFocusListener.onSetFocus = function(oPrevFocus:Object, oNewFocus:Object):Void { trace("Current focus = " + oNewFocus); trace("Previous focus = " + oPrevFocus);
Determining Focus
The getFocus() method returns the full path (as a string) to the currently focused TextField, Button, or MovieClip object. If there isnít any object with focus, a null value is returned. For example, if a text field named tUsername on the main timeline is active, Selection.getFocus() returns _level0.tUsername as a string. Usually, this method is used to assign a value to a variable that stores the path information. Youíll see this usage in later examples.
If a TextFi el d object has both a variable and an instance name assigned, getFocus() returns the path with the instance name. If only a variable name is specified, getFocus() returns the path with the variable name.
Chapter 17 ¶ The TextField and Selection Classes
Working with Selection
A selection is the range of characters within a TextField object that is highlighted. Any time you click and highlight characters within text, you make a selection. You can also make a selection programmatically, as youíll see in just a moment. In input text, you can also insert the I-beam cursor at any position within the field. This position is known as the caret. With ActionScript and the Selection class, you can retrieve the current value of the caretís position, the current position value of the beginning of a selection, and the position value of the end of a selection. You can also use ActionScript to enable automated selections (or highlights) within a text field.
All methods of the Selection class work with zero-based indices.
Note that all of the Selection classís methods for working with the selection and caret do not require you to specify the TextField object for which you wish to set or retrieve the selection. Because there can be only one selection made at a time, the TextField object that currently has focus is automatically used. As you have already learned, a TextField object can receive focus by user interaction or by programmatic means.
A selection has a beginning and an ending point that are given by the respective indices within the focused TextField. In order to retrieve the indices you can use the
Selection.getBeginIndex() and Selection.getEndIndex() methods.
The Selection.getBeginIndex() method returns the starting index of a selection. If there is no selection, the method returns -1. The Selection.getEndIndex() method returns the index of the position immediately after the last character of the selection. If there is no selection when this method is called, the method returns -1.
You can test these methods with the following code:
this.createTextField("tOutput", this.getNextHighestDepth(), 100, 100, 200, 200); tOutput.border = true; tOutput.multiline = true; tOutput.wordWrap = true;
tOutput.text = "The Selection class enables you to retrieve the selected ^ text programmatically."; this.onMouseUp = function():Void {
Previous << 1 .. 201 202 203 204 205 206 < 207 > 208 209 210 211 212 213 .. 419 >> Next