Accessibility

ActionScript cookbook beta

Access root/main timeline of your content

Problem Summary

You need to access the root / main timeline of your content.

Solution Summary

Use the root property to access the root timeline of your content.

Explanation

ActionScript 2

//function on main timeline
      
function foo():Void
{
   trace("foo");
}

//called from anywhere in content
_root.foo();

ActionScript 3

//function on main timeline
      
function foo():void
{
   trace("foo");
}

//called from anywhere in SWF
MovieClip(root).foo();

Note: In ActionScript 2 _root always refers to the main timeline of the main SWF. In ActionScript 3, the root property refers to the main timeline of the SWF in which the content originates. In most cases, these will be the same in either version of ActionScript. The main exception is where the property is being called from within a SWF that has been loaded into another SWF. In ActionScript 2 _root will refer to the main timeline of the main SWF (that loaded the other SWF). In ActionScript 3 the root property refers to the main timeline of the loaded SWF (and not the timeline of the SWF which loaded the other SWF).

The root property is only available in DisplayObject instances (such as MovieClip, Sprite, and Button).