4 Replies Latest reply on Jul 7, 2009 3:08 PM by Rothrock

    Addressing Movie Clips inside a Movie Clip That Has Been Loaded into a ScrollPane

    billgregg

      I'm trying to use the scroll pane component for the first time, and I've spent most of the day getting nowhere. Based on my experience with other components and with loading content into movie clips, I expected that I would point my scroll pane to its content and be off and running, but that hasn't happened.


      Here are the objects:

      (1) A scrollpane component on the stage with the instance name "quiltpane".
      (2) A movie clip in the library with the symbol name "quilt", the identifier "quilt" and Export for ActionScript and Export in First Frame both checked.
      (3) A large number of movie clips inside the movie clip "quilt" (one for each quilt square) that need to be addressed from the main timeline. They have the instance names "square1", "square2", "square3", etc.

      I'm loading the movie clip "quilt" into the scrollpane with a single line:

      _root["quiltpane"].contentPath = "quilt";

      That works fine, but I can't figure out how to talk to the movie clips inside the loaded movie clip "quilt". I've tried:

      _root["quiltpane"]["square1"]
      _root["quiltpane"]["quilt"]["square1"]
      _root["quilt"]["square1"]
      _root["quiltpane"]["content"]["square1"]
      _root["quiltpane"]["content"]["quilt"]["square1"]

      What am I doing wrong?

      Bill Gregg
        • 1. Re: Addressing Movie Clips inside a Movie Clip That Has Been Loaded into a ScrollPane
          Rothrock Level 5

          I don't know if you are supposed to be able to reference the contents directly. The clip they are loaded in is called, I believe, "spHolder". So

           

          quiltpane.spHolder["square"+number]

           

          should get you started. I might have forgotten a nested clip there so you can add a trace to your quilt movieclip.

           

          trace("Current scope is: "+this);

           

          And that will let you see where it is. I can't promise that it will stay that way....

          • 3. Re: Addressing Movie Clips inside a Movie Clip That Has Been Loaded into a ScrollPane
            billgregg Level 1

            Thanks, Rothrock.

             

            I had seen "spContentHolder" used in a couple of online examples, but since it doesn't get formatted as a reserved term in the Actions window I wasn't sure whether it was an ActionScript term or someone's variable name. Since it's an automatically generated name and not a method or a property, I guess the plain-Jane formatting makes sense. I had actually tried "spContentHolder", but I may have had some other part of the path wrong at that time. And of course there's the timing issue. If the movie clip isn't fully loaded, nothing inside it will respond to commands--I'm still working on that.

             

            The scope trace is a nice trick and helped me arrive at the correct path, which at the moment I'm verifying with a button after the movie clip is loaded:

             

            _root["quiltpane"]["spContentHolder"]["quilt"]["square" + loopcount]

             

            Bill

            • 4. Re: Addressing Movie Clips inside a Movie Clip That Has Been Loaded into a ScrollPane
              Rothrock Level 5

              glad that worked out for you. Yes trace is your friend.

               

              BTW you need to use the array notation for everything and it is generally not such a great idea to use _root -- just in case you later load content into another swf the _root will change.

               

              So if this were me....

               

              var sp:ScrollPane=quiltpane

              var myContent:MovieClip=sp.spContentHolder.quilt;

               

              And then later

               

              myContent["square"+loopcount];

               

              Easier to read, easier to type. You can give those different names that are more meaningful for you. Also you will get code hinting since the variables are typed -- you won't get that with the array notation. You could even do something like:

               

              for(var loopcount=0;i<numSquares;i++){

              var curSquare:MovieClip=myContent["square"+loopcount];

              curSquare._alpha=blah blah

              blah blah blah.

              }