Mapping to a Function
There are two basic ways of mapping to a function:
- Using relative or absolute identifiers
In this case, _root refers to the root timeline of the current level the script is run on, and _parent refers to the movie clip or object that contains the movie clip or object with the script. If a script using the _parent object is placed within a movie, the script looks to the movie containing itself. Also, _levelN refers to the n th level in the standalone Flash player or the Flash movie. - Using direct movie names
An example is myMovie.myFunction();. Notice that every movie object or movie name used in dot syntax is separated by a period.
NOTEAlthough it is possible to call functions created on other timelines, it is good practice to keep all functions on the main timeline, or in an external .as file so that you will always know where to find them.Now that you have seen some generic ways for using dot syntax to map to functions, let's look at a few examples of using them:
As mentioned before, using dot syntax is no longer a necessity when trying to reach a function from a timeline that's different from the one it was created on because of the _global identifier.
_root.myFunction () //invokes the function in the _root timeline
_parent.myFunction() //invokes the function in the _parent timeline
_parent._parent.myFunction() //invokes the function in the _parent of the
//_parent timeline
_root.myMovie.myFunction() //invokes the function in myMovie which is
//located on the _root timeline