Return to Kroll Design home page

Flash Tutorials (with .FLA files included)

 
« Return

ActionScript 2

_parent._parent._parent vs _level0 vs _root for accessing main timeline


This example has 3 circular buttons referencing the main timeline in each of 3 ways. See below for the code, which includes comments from an Adobe web site which points out that _root and _level0 can act differently. In this example they act the same, however.

Download the FLA file

/*
  This Action Script is in frame 1 of the timeline for library movie clip 'Radio',
	which contains 3 instances of 'Knob' named myKnob1, myKnob2, and myKnob3.
	
	Below are 3 ways to accomplish the same thing, that is, 3 ways to reference
	the main timeline:
*/

myKnob1.onRelease = function()
{
	_parent._parent._parent.gotoAndStop("page1");		
}


myKnob2.onRelease = function()
{
	_level0.gotoAndStop("page2");	
}


myKnob3.onRelease = function()
{	
	_root.gotoAndStop("page3");	
}

/*
However, as Adobe web site http://kb2.adobe.com/cps/146/tn_14686.html
explains, _level0 and _root don't always give identical results:

"Differences between _root and _level0

At first glance it may seem that _root and _level0 refer to the same thing. However, they are not identical. 

The property _root refers to the main timeline of the movie from which the property was referenced, or the top-most timeline within the current hierarchy of timelines. If an instance of the Flash Player has multiple levels, the main or root timeline is on the level containing the currently executing script. 

The property _level0 references the main timeline of the movie loaded into level 0. This property can be referenced from any level and still reference the same timeline, that on level 0. 

When a SWF file is loaded into the Flash player, it's main timeline is loaded into level 0. In this movie and this movie only will _root and _level0 reference the same timeline. Additional SWF files can be loaded into additional levels using loadMovie or loadMovieNum. References of _root in those files then reference the level in which that SWF referencing _root was loaded. For example, if a SWF is loaded into level 2, a reference to _root in that SWF will reference the same timeline that _level2 references, but will not reference the same timeline as _level0. A reference to _root will only equal _level0 in the SWF that was first loaded into the player (level 0). 

If you are working with levels in ActionScript, you should always use _root to reference the main timeline in your movies. Using _level0 may incorrectly reference the main timeline of another SWF, the first movie loaded into the player. 

Note: ActionScript 3 no longer uses the concept of levels." 

Crystal clear, eh?

*/


 
« Return


©2012 Kroll Design    info@KrollDesign.net    781.910.3694
Last modified: 12/31/1969 7:00 PM