Recipe 9.3. Making a User Input Field


Problem

You want to create a user input field to allow the user to enter text.

Solution

Set the text field's type property to TextFieldType.INPUT.

Discussion

There are two types of text fields: dynamic and input. The default text field type is dynamic. This means that it can be controlled with ActionScript, but the user cannot input text into it. To enable the field for user input, set the type property to the INPUT constant of the flash.display.TextFieldType class:

field.type = TextFieldType.INPUT;

Though it isn't a requirement, input fields generally also have a border and a background. Otherwise, the user might find it difficult to locate and select the field:

field.border = true; field.background = true;

For a user to be able to input text, the field's selectable property must be true, which is the default. You don't need to set the selectable property to true, unless you previously set it to false.

If you have previously defined an input text field that you want to make a dynamic text field (so that it does not accept user input) you can set the type property to the DYNAMIC constant of the flash.display.TextFieldType class:

field.type = TextFieldType.DYNAMIC;




ActionScript 3. 0 Cookbook
ActionScript 3.0 Cookbook: Solutions for Flash Platform and Flex Application Developers
ISBN: 0596526954
EAN: 2147483647
Year: 2007
Pages: 351

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net