Hint, Hint: Flash Helps You Code

     

C ode hints act as a friendly expert watching over your shoulder as you create ActionScript, and giving you hints as you go along. Code hints come in two forms: tooltips and menu-driven code completion .

Tooltips show you formats after you have typed a portion of the action, or inserted an action via another means. For instance, in Figure 19.3, a gotoAndPlay() action has just been dragged from the Actions toolbox into the Script pane, and a tooltips hint has automatically appeared showing that this action requires a frame parameter indicating which frame to go to.

Figure 19.3. The action instanceName.gotoAndPlay() has just been dragged into the Script panel (on the right) from the Actions toolbox (on the left). The tooltip, "MovieClip.gotoAndPlay( frame )" shows the required format for the action.
graphics/19fig03.jpg

Code completion saves you typing by displaying a menu of possible choices, as shown in Figure 19.4.

Figure 19.4. Code completion displays a menu of choices ( _alpha , _focusrect , and so on, in this case) appropriate to the code you have begun to type.
graphics/19fig04.jpg

graphics/new_icon.jpg

You can get menu-style code hints for instances of various classes of objects (such as movie clips, buttons , or text fields) by using strict typing , a new feature that enables you to classify a variable or object when you use AS2 to create it.


For more on strict typing, see "Managing Variables, Data, and Datatypes," in Chapter 20, page 460 .


Figure 19.4 shows the Actions panel with two lines of code. The first line, var myTxt:TextField = new TextField(); , creates a strictly typed text field object. The second line, myTxt. , is an incomplete statement that starts with the name of the new text object, followed by a period. There are only a limited number of ways to complete this statement, according to the rules of ActionScript syntax. As soon as you type the period, Flash lists appropriate possibilities.

An alternative way to get menu-style code hints, which works with AS1 as well as AS2, is to add a class-specific suffix to the name of the object or variable. When you create an object or variable with ActionScript, add the suffix to the object or variable name. If you create an object, such as a movie clip, text with a field, or button, by placing a symbol on the Stage, add the suffix to the instance name. For example, in Figure 19.5, the suffix _ mc has been added to the instance name manystars , forming the name manystars_mc .

Figure 19.5. Flash provides menu-style code hints because a class-specific suffix, _mc (for "movie clip") has been added to the name of the object, manystars .

graphics/19fig05.jpg


The CD accompanying this book has a table of all the code hint suffixes. See Code Hint Suffixes.htm .


Both tooltips and menu-style code hints are enabled by default, but can be disabled if you select Edit, Preferences, ActionScript, and click in the "Code hints" check box. If code hints are enabled, you can enable and disable just tooltips by selecting Edit, Preferences, General, and clicking in the "Show tooltips" check box.



Using Macromedia Studio MX 2004
Special Edition Using Macromedia Studio MX 2004
ISBN: 0789730421
EAN: 2147483647
Year: N/A
Pages: 339

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