Basics
Now that we've begun to delve into ActionScript you need to become familiar with a key concept of most modern programming and scripting languages: dot notation. This is a simple convention by which we describe the affiliation of things, attributes, and actions (objects, properties, and methods) by placing them within a hierarchical scheme or tree structure.
Dot notation reads from the general (left) to the particular (right), or from the root of the tree out to branches and leaves. Here's an illustration.
Suppose I have a Movie Clip called "Scenery" in my main timeline (that is, I've given the Movie Clip this name in the Name slot of the Instance Panel). Embedded within the "Scenery" Movie Clip is another Movie Clip called "visitor," which contains the image of a person. If I want to show just the scene devoid of people, I might execute this statement:
_root.Scenery.visitor._visible = false;
Properties and methods
This example illustrates how dot notation is used to map the affiliations between elements: _root represents the main timeline, .Scenery digs down to the Movie Clip installed within it, and .visitor to the Movie Clip within the Movie Clip.
This example also shows another use of dot notation: to refer to the properties of objects, in this case ._visible, which can be used to make an object seen or unseen. The last element in a dot-notation chain is often not an object but a property of an object.
This last position can also be occupied by a variable. If you want to place text in a dynamic text box, for instance, you name a variable for the box (let's say "display") in the Text Options tab of the Character panel; then you assign a value to this variable by executing a statement such as:
_root.display = "Game Over, Man";
Sometimes the last position in a dot-notation chain will be neither an object nor a variable but a method. You've already seen this with Math.random(). This bit of dot notation invokes the random() method of the special ActionScript Math object. You can also use this technique to invoke a function defined within a handler attached to a Movie Clip. We saw an example of this in the "breakout" demonstrations.
Prefixes and pronoun
Now let's consider the first element in dot-notation strings. This element must always refer to an object, but there are some important variations.
As we've seen, _root refers to the main timeline. If you want to define a variable to be used by more than one script (what programmers call a global variable), you have to define it as _root.whatever (using whatever variable name you like).
Another handy prefix, _parent, refers to whatever object contains the present object. This prefix is used in solving a problem with the gotoAndPlay() method, discussed this week.
Finally, there's also the nifty pronoun this, which refers to the object to which the given script is attached. If you find yourself lost in the dot stream but need only to operate on the current object, this can do the trick.
