4 Replies Latest reply on Jan 17, 2007 5:29 AM by Newsgroup_User

    movie clip nested array

    jagguy99 Level 1
      I have an array of movie clips and want to make the clips nested so i can click on them.
      ..
      this.createEmptyMovieClip("mcc"+i,this.getNextHigh estDepth());
      ..

      To make them nested and be able to click on a MC how can I refer to each MC with a button press with array notation eg
      How can i code a dynamic size MC button press?

      mcc?.mcc?.onPress = function () {
      }
        • 1. Re: movie clip nested array
          Level 7
          jagguy99,

          > I have an array of movie clips and want to make the
          > clips nested so i can click on them.
          > ..
          > this.createEmptyMovieClip("mcc"+i,this.getNextHigh estDepth());
          > ..

          I don't see an array in that example, but I hear you. The important
          distinction to make is whether your array contains movie clip references or
          strings. If it contains references, you may treat each array element as if
          it were a movie clip. If it contains strings, you'll have to manufacture
          that reference.

          > To make them nested and be able to click on a MC
          > how can I refer to each MC with a button press with
          > array notation

          Movie clips are instances of the MovieClip class, so the "button press"
          you're talking about would have to be a MovieClip event, not a Button event.
          As it turns out, movie clips have the same events as buttons, plus others.
          It's a fine point to make, maybe, but important to realize.

          > eg
          > How can i code a dynamic size MC button press?
          >
          > mcc?.mcc?.onPress = function () {
          > }

          I guess you're asking how to use the array access operator, right? If
          that's it, it's pretty easy. In the first part of your example, you have a
          movie clip instance name mcc?, followed by a dot. The array access operator
          wraps the instance name. This operator takes a string.

          ["mcc" + ?].mcc?.onPress = function() {...}

          With me so far? The second part of this path, if it's also dynamic,
          would go the same way.

          ["mcc" + ?]["mcc" + ?].onPress = function() {...}

          ... and so on. Note how the dot is now missing between the movie clip
          instance names. In this example, that question mark would be replaced by --
          I'm guessing -- a number. There's one last thing. The array access
          operator, used in this context, needs to have an object reference in front
          of it. In case of the second mcc part, the first mcc is the preceeding
          object reference. In the case of the first, you'll need something like,
          say, the global "this" operator (without the quotes), to point to the object
          you're in.

          this["mcc" + ?]["mcc" + ?].onPress = function() {...}


          David Stiller
          Adobe Community Expert
          Dev blog, http://www.quip.net/blog/
          "Luck is the residue of good design."


          • 2. Re: movie clip nested array
            jagguy99 Level 1
            thanks for the reply, it must have taken a while to do so I am very grateful.
            • 3. Re: movie clip nested array
              jagguy99 Level 1
              this didn't work
              this["mcc" + ?]["mcc" + ?].onPress = function() {...}

              this did work
              this["mcc" + ?].onPress = function() {...}

              I need to press on a MC and display a larger image . Currently it holds a thumbnail. The problem is that all images are origianlly different sizes making it hard to code cleanly.

              I am not sure how get the current MC thumb image then display the original image to be resized again if too large.
              • 4. Re: movie clip nested array
                Level 7
                jagguy99,

                > this didn't work
                > this["mcc" + ?]["mcc" + ?].onPress = function() {...}

                It does work if you have nested movie clips, which is what it sounded
                like from your description. Replacing the question marks, you might have
                something like this:

                mccA.mccB.onPress = function() {}

                In such a case, you could also refer to those clips with concatenated
                strings:

                this["mcc" + "A"]["mcc" + "B"].onPress = function() {}

                > this did work
                > this["mcc" + ?].onPress = function() {...}

                Okay, that tells me that you don't have nested movie clips -- or that
                the combination of "mcc," and whatever the question mark stands for, refers
                to the inner nested clip you desire.

                The "trick" about refering to path elements with brackets isn't a trick
                at all, really. It's as straightforward as regular dot notation; it's just
                that the array access operator allows you to use strings as part of your
                reference.

                > I need to press on a MC and display a larger image .
                > Currently it holds a thumbnail. The problem is that all
                > images are origianlly different sizes making it hard to
                > code cleanly.

                I'm not convinced that clean coding isn't possible. But at the same
                time, I'm having a hard time understand your needs here.

                > I am not sure how get the current MC thumb image
                > then display the original image to be resized again if
                > too large.

                That's two goals: a) how to get the current MC thumb image, and b)
                display the original image. Assuming the thumb has the instance name
                "thumb" in each movie clip ...

                this["mcc" + ?].thumb.onPress = function() {}

                The second part, b, I don't follow. If the original image is hidden,
                how are you hiding it in the first place?


                David Stiller
                Adobe Community Expert
                Dev blog, http://www.quip.net/blog/
                "Luck is the residue of good design."