4 Replies Latest reply on Feb 19, 2007 11:56 AM by frenchi30

    looping thru timeline

    frenchi30 Level 1
      Hi there,
      I am trying to convert some AS2 code to AS3 with some difficulty... I am trying to loop over a movieclip and return all the names of the NESTED MC's..... in AS2:

      for (var i in this) {
      if (typeof (this ) == "movieclip") {
      trace(this[name]);
      }
      }

      'this" in AS3 is different, I can see that but what property or method do I use to iterate over the children of "this" (my MovieClip) in AS3?

      Thanks in advance..
        • 1. Re: looping thru timeline
          _Albertx_ Level 1
          Use this.

          for each(var obj:DisplayObject in this.getChildren()){
          trace(obj); // the reference to the object
          trece(obj.name); // the name "id" of the object
          }
          • 2. Re: looping thru timeline
            frenchi30 Level 1
            hi there, thank-you verymuch for the reply, but I get an error:

            TypeError: Error #1006: getChildren is not a function.

            what does this mean?
            thank-you
            • 3. Re: looping thru timeline
              _Albertx_ Level 1
              Ah ok ok, sorry.

              I know the problem...

              Well, getChildren() is a method from the Container class which is in the Flex Framework, but it's not directly in ActionScript 3.0 class, that's why the compiler can find it.

              Ok, replace the previous code with this.

              var n:int = this.numChildren; //property which gives you the number of elements inside the DisplayObjectContainer, in this case "this"
              for (var i:int = 0; i < n; i++)
              {
              var element:DisplayObject = this.getChildAt(i);
              }
              • 4. Re: looping thru timeline
                frenchi30 Level 1
                This is great thank-you very much.
                Just one more thing please.. How could I get it to loop thru the whole swf? This seems to loop only in the first container..(this)
                What I mean is, how can I loop thru the children of the containers? nested loops?
                I am new to all this, sorry for the beginner questions..

                thank-you