What is the difference between object main timeline, object Stage and root in as3?

前端 未结 3 372
谎友^
谎友^ 2020-12-16 20:17

I want to know the difference between [object main timeline], [object Stage] and root in as3?

I have read from the topic How

相关标签:
3条回答
  • 2020-12-16 20:45

    I think the article you linked to sums it up quite nicely (even if it doesn't explain it all that well):

    To summarize: one stage, one root per SWF (which is the main timeline) and that root is an instance of a document class or the MainTimeline class if a document class isn't provided

    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:

    trace("this " + this);
    trace("root " + root);
    trace("root.parent " + root.parent);
    trace("stage " + stage);
    trace("parent " + parent);
    

    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.

    this [object MainTimeline]
    root [object MainTimeline]
    root.parent [object Stage]
    stage [object Stage]
    parent [object 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.

    enter image description here

    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.

    this [object Test]
    root [object Test]
    root.parent [object Stage]
    stage [object Stage]
    parent [object 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.

    0 讨论(0)
  • 2020-12-16 20:48

    root is the main (uppermost) part of your movieclip

    When you create an object in the library and edit it, the timeline you see is the object timeline and the stage you see is the object stage.

    Object timeline and stage are independent of the main (_root) timeline

    0 讨论(0)
  • 2020-12-16 20:55

    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.

    0 讨论(0)
提交回复
热议问题