Creating Scriptable Text Objects

I l @ ve RuBoard

In Chapter 2, you learned to create editable text blocks. But in the published movie, that text is just a graphic element, not an object that ActionScript can interact with. Only text within text boxes whose type is Input or Dynamic can be manipulated with scripts.

To enable ActionScript to recognize the text box and manipulate its properties, you must give the text box an instance name. Although text boxes have different properties than movie clips, the procedures for naming and targeting a text box instance are just like those you learned for targeting movie clip instances earlier in this chapter. You can also give a dynamic or input text box a variable name and use ActionScript to target the variable, thereby manipulating the contents of the text box.

A variable is basically a container for storing information. That information could be numbers , letters , or mathematical formulas. The important thing about variables is that they are, well, variable and that ActionScript can put things into them and take things out of them, and generally muck about with their contents.

The container might be represented by an element in your movie, or it might be just an abstract container in Flash's electronic brain. It's easiest to start with the more concrete version. Create a text box into which your viewers can enter information: the input text box. Next, create a text box in which the results of your manipulation of that information will appear: the dynamic text box. (You'll learn about doing the actual manipulation in the next section.)

The Mystery of Naming Variables

In naming variables, you must always start with a letter or an underscore character. To make the variable name a sort of mnemonic description of itself, you can use multiple words or word fragments , but you cannot use the space character to separate the words. ActionScript reserves the space character to act as a separator between action statements. Instead, use internal capitalization to make the multi-word names easier to decipher ( myVariable , for example). You can also use the underscore character as a separator. All other punctuation, however, is forbidden in variable names.

Instance Names versus Variables for Text Boxes

Flash gives you two ways to name and target a text box, the instance name and the variable name. Usually, you will want to use an instance name. You must use instance names if you want to control the text field itself, using ActionScript to reposition it or change its size or rotation or font, for example. When you give the text box a variable name, the box displays the contents of the variable; by using ActionScript to change the variable's content, you can display new content within the text box. Using ActionScript to change the text property of the text box instance allows you to manipulate and change its contents without using variables.

To create an input text box:

  1. Open a new Flash file.

  2. In the Toolbox, select the text tool.

  3. In the Property Inspector, from the Text Type pop-up menu, choose Input Text. The panel displays the parameters for text boxes that allow users to enter text (Figure 15.5).

    Figure 15.5. To access the parameters for creating text boxes that accept input from your movie's viewers, choose Input Text from the Text Type pop-up menu. The input parameters control the field's appearance and functiongiving the text field a border and background, for example, so that the field is visible in the final movie even if it's empty.

    graphics/15fig06.gif

  4. On the Stage, in Keyframe 1, create a text box that contains the word Age .

  5. To assign a name to the variable, in the Property Inspector's Variable field, enter ageVAR (Figure 15.6).

    Figure 15.6. To assign a variable name to a text box, enter the new name in the Variable field.

    graphics/15fig05.gif

    Giving the variable a name makes it recognizable to Flash via ActionScript. You use this variable name when you write scripts. You might, for example, tell Flash to retrieve whatever data your movie viewers enter in the text box with this variable name.

  6. To make your text box visible in the movie even when the box contains no text, click the Border button.

  7. To restrict the length of the text box, in the Maximum Characters field, enter 3 . This setting prevents users from inadvertently typing an impossible age.

  8. To allow viewers of your movie to select and replace the word Age in the published movie, click the Selectable button (Figure 15.7).

    Figure 15.7. To create an input text box that allows end users to select the contents of the text box before entering new text, click the Selectable button in the Property Inspector for text.

    graphics/15fig07.gif

  9. Leave all other options at their default settings.

graphics/01icon02.gif Tips

  • To ensure that text boxes in the published movie look exactly as you planned, you can include outlines for rendering all (or part) of the font used in your input text box. Click the Character button in the bottom-right quadrant of the text Property Inspector to access the Character Options dialog box. You can opt to embed font outlines for all characters or various subsets of characters. Or you can skip embedding font outlines altogether.

  • The letters VAR in this variable's name are not required; they are just a mnemonic device. As you begin to learn ActionScript, such reminders can help you determine of what type of item you are dealing with when you see it in the somewhat cryptic context of a script.


To create a dynamic text box:

  1. Using the file you created in the preceding exercise, with the text tool create a text box that contains the words Lucky Number .

  2. With the text box still active, access the Property Inspector for text.

  3. From the Text Type pop-up menu, choose Dynamic Text.

    The Property Inspector displays the parameters for dynamic text (Figure 15.8).

    Figure 15.8. The Dynamic Text parameters are similar to the Input Text parameters.

    graphics/15fig08.gif

  4. In the Variable field, enter LuckyNumVAR .

  5. To prevent viewers from typing in this field accidentally , uncheck the Selectable checkbox.

  6. Leave all other options at their default settings.

graphics/01icon02.gif Tip

  • In this example, the text boxes don't contain lengthy text. If you need to, you can make dynamic or input text boxes scrollable either as you create them or via ActionScript. To create scrollable text boxes during authoring, with the arrow tool, select the text box. Then Control-click (Mac) or right-click (Windows) the text box, and from the contextual menu, choose Scrollable.


I l @ ve RuBoard


Macromedia Flash MX for Windows and Macintosh. Visual QuickStart Guide
Macromedia Flash MX 2004 for Windows and Macintosh (Visual QuickStart Guides)
ISBN: 0582851165
EAN: 2147483647
Year: 2002
Pages: 243

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