Input Text Tab Order

I l @ ve RuBoard

In Flash 5, one of the biggest complaints that developers had was that they could not set the Tab order of input fields. Tab order refers to the automatic movement of the cursor between input fields when the user presses the Tab key. This happens in all professional applications such as Web browsers. Users have come to expect that when they press Tab, the cursor will move to the next logical field.

However, Flash's choice for the next logical field is not always correct. After all, Flash can only assume so much based on the position of the fields. For instance, in Figure 15.5, Flash assumes that the field after the first one is the field under it, not across from it.

Figure 15.5. These fields are not laid out in the obvious Tab order.


Fortunately, you can override Flash's automatic Tab order with the tabIndex property of a text field. So if the field variables range from text1 to text4 , you could use this to set Flash straight:

 text1.tabIndex = 1; text2.tabIndex = 2; text3.tabIndex = 3; text4.tabIndex = 4; 

When using tabIndex , take care to label all the text fields, leaving none undefined. Also avoid using the same number twice. This will confuse Flash.

One thing that neither the default Tab ordering nor the use of tabIndex does is to automatically set the focus on the first field. To do that, you have to use a command in the Selection object to specifically tell Flash that you want the cursor to appear there.


This command can be used at any time in any way you want. It makes the cursor jump to any field you want. However, its most obvious use is to start the cursor off in a field instead of requiring the user to click in it before typing.

You can also use Selection.getFocus() if you need to know where the cursor is located. If you want to know when the focus has been changed, you can set a listener to watch for it. Here is an example:

 Selection.addListener(this); this.onSetFocus = function(oldFocus, newFocus) {     trace(oldFocus+","+newFocus); } 

You can see this script active in the movie 14taborder.fla. Every time you Tab to a different field, references to the previous field and the current field are sent to the Output window.

You could use a listener like this to monitor the progress of a user entering data into a form. If the user Tabs away from a field, you could check the data in that field to see whether the user entered enough characters or entered the right sort of characters. We'll look at an example at the end of this hour .

I l @ ve RuBoard

Sams Teach Yourself Flash MX ActionScript in 24 Hours
Sams Teach Yourself Flash MX ActionScript in 24 Hours
ISBN: 0672323850
EAN: 2147483647
Year: 2002
Pages: 272 © 2008-2017.
If you may any questions please contact us: