3 Replies Latest reply on Jul 7, 2008 2:00 PM by Ghost Of Death

    What's the diffirent between _root & _parent

    Ghost Of Death
      Hey guys, can anyone explain for me whats the diffirent between _root and _parent with giving examples ?!

      thanx :)
        • 1. Re: What's the diffirent between _root & _parent
          the _root takes you to the main scene of the project

          but the _parent takes you only one level up starting the object where you are

          for example:
          i have a MovieClip (Which is called MC2) inside another MovieClip (Which is called MC1) and the main scene which is called (Scene1)
          and now i'm in the MC2, for now i want to apply an action to MC1 or the main scene (Scene1)
          the code should be written like this:

          _Parent.stop(); this will stop the motion which is in one level up
          and here it's (MC1)
          _Root.stop(); will stop the motion in the whole scene
          and here it's (Scene1)

          hmm i hope that it's got more clarity now
          tell me if it's not
          • 2. Re: What's the diffirent between _root & _parent
            Level 7
            Ghost Of Death,

            > Hey guys, can anyone explain for me whats the diffirent between
            > _root and _parent with giving examples ?!

            _root is a global property. That means it isn't associated or attached
            to a particular object, such as a movie clip. In other words, you can
            reference it from any pre-ActionScript 3.0 script, and it gives you a
            reference to the main timeline. Prior to ActionScript 3.0, the main
            timeline is always a movie clip, so if you mention _root:


            ... you can safely peg movie clip-related functionality after it, such as:


            It doesn't matter where that one-line script appears -- might be on the
            main timeline itself, or buried deep in some nested timeline of a movie clip
            symbol -- the expression "_root" (minus the quotes) always points to the
            main timeline.

            The key, then, is what the phrase "the main timeline" means. This is
            where _root can get tricky, and where it often catches a bad rap from
            programming purists. Why? Because the "main timeline" isn't always what
            you think it is. Prior to ActionScript 3.0, Flash Player is capable of
            loading or creating content in something called levels, which is comparable
            in some ways to opening more than one image in Photoshop (or more than one
            document in MS Word, etc.). Levels are Flash Player's way -- one of its
            ways -- of opening more than one SWF. (ActionScript 3.0 is still capable of
            opening numerous SWFs, but the mechanism has changed.)

            So ... if you've loaded or created content in _level1, _level5,
            _level22, and so on, and if code is currently executing in one of those
            levels, then any reference to _root in that code is a reference to the main
            timeline of *that* level (_level1, _level5, or _level22). By default,
            content plays in _level0, so unless other levels are used, _root refers to

            It gets better. If you create a SWF that refers to _root, and your SWF
            gets loaded into *another* SWF, then any reference to _root in the loaded
            SWF points to the *containing SWF's* main timeline (of whatever level is
            currently executing code). Unless ... unless, the MovieClip._lockroot
            property is set to true for the loaded SWF.

            As you can see, _root has the potential to get pretty convoluted. Many
            programmers hate it -- even to the point of promoting "_root is evil"
            campaigns. The choice is yours, of course. ;) If you understand _root and
            its implications, go ahead and use it. It's a tool, even if it's a dated
            one. I sometimes use _root when I'm creating simple content that won't be
            loaded into other content.

            _parent is a property of the MovieClip class, but a number of other
            classes feature the same concept (Button, TextField, and Video come to mind;
            there might be more). So, what does it mean to be a property of a class?
            In ActionScript, everything that's an object is defined by a class. What's
            an object? Anything you can manipulate with code. Movie clips are objects,
            text fields are objects; so are blur filters and drop shadows. XML nodes
            are objects, stylesheets (CSS) are objects; arrays, dates, and collections
            of math functions are objects. Objects are defined by classes. When you
            draw a shape and convert it to a movie clip, you've created an instance of
            the MovieClip class. When you use "new Array()" (without the quotes),
            you've created an instance of the Array class.

            Movie clips have width and height, x and y positions, and other tangible
            characteristics. Such characteristics are called properties. The _parent
            property of the MovieClip class refers to the object that contains the movie
            clip in question. So if you have this line in the keyframe script of a
            movie clip:


            ... you're telling the timeline that *contains* this clip to go to frame 15
            and play. Parent objects are usually movie clips. Off hand, I can't think
            of a case in which the parent would be anything else. If you reference the
            _parent property of a text field, it would be a movie clip, because text
            fields can't be nested. Anyway, the point is that _parent refers to the
            immediate parent of the object in question. If you reference the _parent
            property of a movie clip that is nested 12 timelines deep, then you're
            refering to the 11th timeline. That's a big different from referencing
            _root, which skips all the way to the main timeline.

            David Stiller
            Co-author, Foundation Flash CS3 for Designers
            "Luck is the residue of good design."

            • 3. Re: What's the diffirent between _root & _parent
              Ghost Of Death Level 1
              thaaaaaaaaaaaanks for both of you guys ^_^ i got it now ^_^