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 nth 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.

NOTE

Although 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:

 _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 

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.




Macromedia Flash Professional 8 Unleashed
Macromedia Flash Professional 8 Unleashed
ISBN: 0672327619
EAN: 2147483647
Year: 2005
Pages: 319

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