5 Replies Latest reply on May 17, 2006 1:50 PM by Rothrock

    Looping through all child movies of a movieclip

    Level 7
      I am loading some movieclips that have a variable number of sub-movieclips
      contained within. Each of these sub-movieclips has an object associated
      with it that gives some points of distortion. My question is this...

      I could have as few as 1 sub-movieclip or as many as 10+. Once the main
      movieclip is loaded I apply an onRollOver event handler to the it and that
      works fine. But, now I want to loop through each of the sub-movieclips and
      apply a distortion to them based on the object contained within the
      sub-movieclip. So, how can I loop through the sub-movieclips?

      If this doesn't make sense... sorry, maybe this will help.

      piece1.swf contains the following movieclips:
      left_piece1_1
      left_piece1_2
      left_piece1_3
      right_piece1_1
      right_piece1_2
      and each of these 'sub-movieclips' contains an array of Points corresponding
      to points used for a distortion I apply. Without adding extra variables to
      the movieclip being loaded, how can I loop through each of the MCs?

      Thanks for any and all help.
      Amy


        • 1. Re: Looping through all child movies of a movieclip
          Rothrock Level 5
          Check out for...in in the help files. Something like the code below. However it will loop through all the children so you might need to check to see if the returned object is a movieclip.

          • 2. Re: Looping through all child movies of a movieclip
            Level 7

            "Rothrock" <webforumsuser@macromedia.com> wrote in message
            news:e4fo3p$o9b$1@forums.macromedia.com...
            > Check out for...in in the help files. Something like the code below.
            > However it
            > will loop through all the children so you might need to check to see if
            > the
            > returned object is a movieclip.
            >
            >
            >
            > for(var a in myMovieClip){
            > trace(myMovieClip[a])
            > }
            >


            Thanks Rothrock... I had just found that. But, now another question.

            There are several additional attributes to the myMovieClip then just the
            sub-movieclips but I want to isolate just instances of movieclips so I was
            trying something like this...

            for (var i in selectionArea) {
            if (selectionArea instanceof MovieClip) {
            trace(i);
            }
            }

            but nothing gets traced. How can I isolate these MCs?

            Thanks!!!


            • 3. Re: Looping through all child movies of a movieclip
              Level 7

              "Rothrock" <webforumsuser@macromedia.com> wrote in message
              news:e4fo3p$o9b$1@forums.macromedia.com...
              > Check out for...in in the help files. Something like the code below.
              > However it
              > will loop through all the children so you might need to check to see if
              > the
              > returned object is a movieclip.
              >
              >
              >
              > for(var a in myMovieClip){
              > trace(myMovieClip[a])
              > }
              >

              I also tried

              if (typeof(selectiohnArea == "movieclip")) {
              do stuff;
              }

              but that is returning true for all vars in myMovieClip including onRollOver
              and onRelease.



              • 4. Re: Looping through all child movies of a movieclip
                Level 7

                "Amy G" <amy-g-art@cox.net> wrote in message
                news:e4fpit$qas$1@forums.macromedia.com...
                >
                > "Rothrock" <webforumsuser@macromedia.com> wrote in message
                > news:e4fo3p$o9b$1@forums.macromedia.com...
                >> Check out for...in in the help files. Something like the code below.
                >> However it
                >> will loop through all the children so you might need to check to see if
                >> the
                >> returned object is a movieclip.
                >>
                >>
                >>
                >> for(var a in myMovieClip){
                >> trace(myMovieClip[a])
                >> }
                >>
                >
                > I also tried
                >
                > if (typeof(selectiohnArea == "movieclip")) {
                > do stuff;
                > }
                >
                > but that is returning true for all vars in myMovieClip including
                > onRollOver and onRelease.


                I feel like a moron. Incorrect placement of my parenthesis got me here...

                The way I have in my previous post (listed above) would evaluate the boolean
                of the result of comparing selectionArea
                to "movieclip" which of course
                would be either true or false and would thus return "boolean" for typeof
                every time.

                Here is how it should be.

                if (typeof(selectionArea ) == "movieclip") {
                do stuff;
                }


                Thanks again.


                • 5. Re: Looping through all child movies of a movieclip
                  Rothrock Level 5
                  Glad you worked that out. Don't you feel like you've achieved something today!