5 Replies Latest reply on Aug 28, 2007 8:54 PM by SummerLongSince

    addressing long chains of nested clips in AS3

    SummerLongSince
      Hi,
      this is probably a very easy topic, but i haven't been able to figure it out myself.
      In my example i have a class that creates 3 clips (sp1, sp2, sp3) and places them on the stage. In addition they are nested:
      sp3 inside sp2,
      and sp2 inside sp1.

      From my main flash movie I am trying to address those clips. it works it if I do things like:
      sp3.x=70';
      sp2.y=100;
      etc.

      But I want to know how I can address clips in a fashion similar to what it used to be possible in AS2.

      If i type this:
      sp1.sp2.sp3.x=70;
      I get this error message: TypeError: Error #1010: A term is undefined and has no properties.

      What is the new way to do this please?
        • 1. Re: addressing long chains of nested clips in AS3
          SummerLongSince Level 1
          well, i kept poking around and found a way to address the nested clips in a long chain. It just takes too many lines of code (at least 7) for something that before could be done in 1 line. So I'm not sure it this is the best approach.

          In the class definition i created names for each of the clips (using the name property).

          and then in my main flash movie: I coded this:

          var tempClip:*;
          var tempClip2:*;
          tempClip = sp1.getChildByName('sp2');
          tempClip2 = tempClip.getChildByName('sp3');
          tempClip2.x=70;

          Is there a better approach? Thanks.

          • 2. Re: addressing long chains of nested clips in AS3
            SymTsb Level 2
            Try this....

            MovieClip(sp1).MovieClip(sp2).MovieClip(sp3).x = 70;

            Personal though, if you are creating your clips on the main timeline of your movie using var = new, it is so much easier to simply access the clip in question using it's variable name in AS3 rather than going through the messes of accessing nested clips.
            • 3. Re: addressing long chains of nested clips in AS3
              SummerLongSince Level 1
              hi SymTsb,

              Thanks for your suggestions. I tried the first one: using

              MovieClip(sp1).MovieClip(sp2).MovieClip(sp3).x=70

              got this error message:
              TypeError: Error #1006: MovieClip is not a function.

              If i try this instead:
              MovieClip(sp1.sp2.sp3).x = 70;

              the error I get is:
              TypeError: Error #1010: A term is undefined and has no properties.

              I am curious about your 2nd suggestion, but I'm not sure how to implement it. I wonder if you can expand more on it.

              I am thinking on situations when you need to address a nested clip and have many copies of the parent clip already on stage. In this cases The instance names of all the parent clips will always be different, but the nested clip may all have the same instance name. So you need a way to specifically address the nested clip of one of many parent clips.
              • 4. Re: addressing long chains of nested clips in AS3
                SymTsb Level 2
                My second option refers to using variable declaration with the new operator. It's the method for creating empty movieclips and attaching them from the library from AS. Here's the code....

                • 5. Re: addressing long chains of nested clips in AS3
                  SummerLongSince Level 1
                  this works.
                  thanks so much.