I want to know the difference between [object main timeline]
, [object Stage]
and root
in as3?
I have read from the topic How stage, root, and MainTimeline Fit Together. But I didn't get clearly.
I want to know the difference between [object main timeline]
, [object Stage]
and root
in as3?
I have read from the topic How stage, root, and MainTimeline Fit Together. But I didn't get clearly.
Root is especially different, in that it doesn't seem to receive mouse events. Can anyone confirm this? You can draw on the root, add solid objects to it, etc... but if you add a listener to the stage, the root, and the object being clicked, you'll find that the event bypasses the root. It seems that even though the root rests between the stage and all other objects in the display hierarchy, all events skip right over it when bubbling.
root
is the main (uppermost) part of your movieclipWhen you create an object in the library and edit it, the timeline you see is the
object timeline
and the stage you see is theobject stage
.Object timeline and stage are independent of the main (
_root
) timelineI think the article you linked to sums it up quite nicely (even if it doesn't explain it all that well):
Stage is probably the easiest to understand. There is one stage per Flash Player - think of it as the window that the Flash movie plays in. It is the top-most display object - anything that appears on the screen is a child of the stage. The stage is always the same instance and any reference to stage returns the same value.
Root is the a logical "top" of the display hierarchy for a specific SWF file. As explained in the article, every SWF will have it's own root, which refers to the instance of the document class for that SWF.
You can see the different between root and stage when loading one SWF into another at run-time. Both SWFs will have a different root but the same stage. The root in each SWF will refer to the top-most display object of their own SWF which is their document class.
MainTimeline is the default class used for the document class. The document class is the display object which is added to the stage when the SWF movie is loaded. Underneath it is a normal class which extends MovieClip.
The document class is the MovieClip you see in the Flash editor. This it is where timeline code is kept and where timeline animations are added. The document class can be over-ridden with a custom class. Changing the document class will change the name of the object that root refers to.
Just as I am referred to as "Human", the timeline is referred to by default as "MainTimeline". If my atoms were to be mangled in a tele-porter and I was changed to a different type of thing such as "FreakOfNature", this would be similar to changing the document to a different class - the result is that the timeline would become a different type of thing.
Here's a test you can do to illustrate how the stage, root and document relate:
1.Create an empty FLA file, and add the following timeline code:
2.Run the FLA and take note of the output. Note that the timeline code is in a class that extends movie clip of name "MainTimeline". This is the same instance referred to by root. The parent of the MainTimeline instance is Stage.
3.Set the document class to your own class (eg: "Test"). Note that the class doesn't actually have to exist - Flash will prompt you to create it automatically.
4.Run the FLA and note the new output. Note that the timeline code is now in a different class that extends movie clip called "Test". "Test" is the type of the movie clip which is added to the stage.
From this we can see that Flash uses a default class named MainTimeline for the document class, unless over-ridden with your own. An instance of the document class (be it MainTimeline or your own class) is added to the stage when the SWF is loaded.