Using Code Hints in the Actions Panel


Code hinting is a feature found in the Actions panel when you are typing out your own ActionScript. Code hints can really save time when scripting and even helps reduce many of the typos and errors that might break your scripts.

Code hints can be invaluable if you are trying to enter text into a text field and can't remember which property to use. There are two ways to open the drop-down menu: strict typing the variable or adding suffixes to the variable. You've already seen examples of using suffixes throughout this book.

To get code hints to appear, you must name your variables, objects, and symbol instances in particular ways, orbarring thatdata type your objects. When you create a variable name, it's just a variable name that stands for anything from a number that's a score in a game to XML data. Strict data typing or suffixes tell Flash what data type (class) the variable belongs to. If you specify what kind of data that variable is for, the code hints show the correct methods and properties for that class. You've seen data typing earlier in this lesson, and the previous figure shows an example of code hints appearing when referring to a data typed object in the script.

The second way to specify the type of variable is to use suffixes. This procedure isn't as flexible as data typing because the suffixes have to refer to ActionScript objects (classes) such as the Sound class or the MovieClip class. By ending instance names for objects in your FLA file with suffixes such as _mc (MovieClip), _btn (Button), _txt (TextField), _str (String) or _lv (LoadVars), Flash provides the proper code hints for that instance. Although not every one of the suffixes provides code hints (notably _gr because you cannot write ActionScript for a graphic), one of the other major benefits of following this naming scheme is that it makes it much easier to remember what data type each symbol is within the library of the FLA file. An example of variable suffixing follows:

var homeContent_lv = new LoadVars(); homeContent_lv.load("home.txt");

Remember that each time you refer to the homeContent_lv variable in the ActionScript, the lv suffix should be appended because it is part of the variable name. Not every data type has an associated suffix (for example, Object has no suffix). Therefore, it might be necessary to use a couple of the methods listed in this section to provide code hints for each of your different variables.

There is a third way to get Flash to display code hints: by typing the data type (the kind of data the variable holds, such as a String, Number, Movie Clip, LoadVars, and so on) and variable name within a comment, such as:

// LoadVars homeContent; homeContent.load("home.txt");

A comment is a message that you type within the ActionScript code, usually to tell yourself or others what is happening in the code at that point, or as reminders of things to do. Comments do not actually execute any code. However, when you use a comment in this way, you are effectively data typing the ActionScript object (in this case, a LoadVars object). Therefore, as soon as the dot is typed after the variable name, the Actions panel opens a list of available methods and properties for the LoadVars object, just as in the preceding example.

Whatever way you choose is completely up to you. If you can't make up your mind, you can even combine the methods, as in the following code:

var homeContent_lv:LoadVars = new LoadVars();

This code has the advantage of using a suffix that can help you remember what the variable is throughout your code, and it also uses strict data typing that makes sure you don't accidentally try setting the variable to the wrong data type such as a Number or String.




Macromedia Flash 8. Training from the Source
Macromedia Flash 8: Training from the Source
ISBN: 0321336291
EAN: 2147483647
Year: 2004
Pages: 230
Authors: James English

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