User Name and Password - Advanced Features - Step Three: Setting up the Tab Key
Posted by : PhilS on Sep 15, 2008
1. Now add a new button called: Tab 2. Move the Button: Off Stage
Note: You can add any standard Button from the Common Library: Window - Other Panels - Common Libraries - Buttons
In my example I have left the Tab button on the stage for demonstration purposes. Normally the Tab button is moved off the stage. It is better that it is invisible.
My Tab button is visible - but there is no need for this.
3. Now add the following ActionScript to the Tab button:
/* Important Note: This Button should be moved off the stage. I have left it on the stage so that you can see it. Normally it should be off the stage and out of sight. When the user presses the tab button this code is run. */
on (keyPress "<Tab>") {
/* Checks the value of variable 'a', if it's equal to 0 then it will set the focus on the User Name and change the variable value to 1. Remember that in the layer ActionScript on the first frame, we set the variable 'a' as 1 by default. So when the Tab button is first pressed, the Movie knows that the user name input box already has the cursor/focus in it. */
if (_root.a == 0) {
Selection.setFocus("_root.UserName");
Selection.setSelection(length(/:UserName), length(/:UserName));
_root.a = 1;
} else {
/* If the User Name has focus, then the code sets the cursor on the Password input box and sets the variable 'a' to 0. So next time it will be picked up by the first if statement above. */
Selection.setFocus("_root.Password");
Selection.setSelection(length(/:Password), length(/:Password));
_root.a = 0;
}
}

no comment
Add comment