• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint

Dot Syntax

ActionScripting uses what’s called dot syntax. You’ve already seen this in effect throughout this chapter. When we used someClip._y, it could be translated to “someClip’s _y property.” (Think of the dot as a possessive s.) In this way, the dot separates a clip instance name from its property. If you have clips nested inside of other clips, you can use dots to separate the nested clip names (_root.someClip._y or someClip.subClip._y, for example). You can also use dots to separate clip names from their respective variables. (This fact is probably easiest to learn if you think of variables as custom properties.) Finally, the dot is used to separate a clip name from the method (or action) when you want to apply the method to an individual clip (someClip.gotoAndPlay(2), for example).

The form of dot syntax is interesting because it always reads left to right, from general to specific. In speech, we usually refer to things from specific to general. For example, “The age of the mayor of Portland, Oregon” reads from specific to general. If these were nested clips in Flash, however, it would read the other way: Oregon.Portland.Mayor.age. Depending on whether your target path is relative or absolute, the length might change, but it’s always from general to specific. (Chapter 7 discusses relative and absolute paths in greater detail.)

Dot syntax is quite easy to learn. Just remember that you can’t name variables or clips with periods in their name. Also, although you’re allowed to name clips with spaces (but you shouldn’t), you can never name variables with spaces in their names. You might imagine if your clip name were “clip.one,” there would be no way to tell whether clip.one._y referred to the _y property of the clip “one” inside the clip “clip” or to the _y property of a clip named “clip.one.” By avoiding periods and spaces in clip and variable names, you avoid this issue. Finally, you shouldn’t name clips or variables beginning with a numeral. To summarize: Clip instance names and variable names should include no spaces, no periods, and never start with a number.

  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint