7 Replies Latest reply on Dec 4, 2008 4:27 AM by Ned Murphy

    Load library clip into target on stage

    Karl_Clay_LA
      Hi. Wouldn't bother anyone with this but have been at it for hours and am at max frustration level. I'm using Flash CS3. I want to rollOver a button on the stage which will load a movie clip from my library into a movie clip that is currently sitting on the stage.

      The desired effect would be comperable to using the loadmovie command and loading an external .swf into a target on the stage. Except in my case I want to load a clip located in my library into the target, instead of having to load an external swf file. Make sense? The objective of doing it this way is I want the loaded clip to sit there on the stage while the cursor mills about. But when the cursor rolls over another button, I would like a different clip in the library to replace the one previously loaded by the first button.

      Any suggestions would be greatly appreciated. Please be specific as I tend to get lost easily with this stuff. Thank you in advance.
        • 1. Load library clip into target on stage
          Ned Murphy Adobe Community Professional & MVP
          First you need to designate the object in the library as an item that can be loaded dynamically.

          Right click on it in the library and select Linkage from the menu that appears. In the interface that appears, select Export for Actionscript. A linkage name will automatically be assigned in the Identifier box, which you can change as you like (lets just say you name it MyObject). This is the name you will use to call in the item from the library.

          To add the item to the movieclip, use the attachMovie method...

          existingMC.attachMovie("MyObject", "instanceNameString", existingMC.getNextHighestDepth());

          Look up attachMovie in the help files to get a good handle on what's going on there.

          I revised this response from an AS3 version of the story, so hopefully I didn't screw up.
          • 2. Load library clip into target on stage
            Karl_Clay_LA Level 1
            Hmmm, yea I was messing with attachmovie to no end today with no success but your code is different and much clearer than what I was trying. I tried what you have above but with no luck because I am not sure what I put in the "instanceNameString" area. My clip is named "Area 1 Web 1", has the linkage name of Area1Web1 assigned to it, and is located in my library in a folder called "Area 1" so would the instance name string be something like "Area 1.Area 1 Web 1" ?

            Here's what I'm using to make the button load the "Area1Web1" clip into a clip with an instance name of "target" sitting on the stage. (I'm assuming target would be the "existingMC" as you describe it.) Not sure what to include in the instanceNameString area though.

            (Thanks for your time, you are really saving me here BTW.)

            • 3. Re: Load library clip into target on stage
              Ned Murphy Adobe Community Professional & MVP
              The instanceNameString is just a name you assign to the instance, any name. It ends up being the instance name of the object that you can use to control it.

              on (rollOver) {
              var instanceName = "anyName";
              target.attachMovie("Area1Web1", instanceName, target.getNextHighestDepth());
              }

              OR

              on (rollOver) {
              target.attachMovie("Area1Web1", "anyName", target.getNextHighestDepth());
              }
              • 4. Re: Load library clip into target on stage
                Karl_Clay_LA Level 1
                Ned: Success! Thank you.

                on (rollOver) {
                target.attachMovie("Area1Web1", "anyName", target.getNextHighestDepth());
                }

                ...loads the clips beautifully.

                I notice the clips are stacking on top of each other instead of replacing each other like they do when loaded from external swf files. I could work around this by placing a solid background in the back of each clip, but is there a different approach you would suggest?

                Thank you again.
                • 5. Load library clip into target on stage
                  Ned Murphy Adobe Community Professional & MVP
                  If you want to replace what's already been placed with something new, then specify a depth rather than using.... target.getNextHighestDepth().... which always goes to the next depth value

                  If target doesn't hold any other wildlife that you'd endanger, just use... 1 (I think). In any case, you can find out the safe value ahead of assigning that value in stone using... trace(target.getNextHighestDepth()); before you attach anything.

                  on (rollOver) {
                  target.attachMovie("Area1Web1", "anyName", 1);
                  }

                  Crap!... I forget if doing that merely pushes the formerly loaded item to another depth, probably does with my luck. If so, use target.removeMovieClip(); before you attach a new one. The bottom line I always try to offer... look it up in the help files... they are your friend (once you get familiar with them).

                  Cool!... I spent some time with that friend I just mentioned and found this diamond in the rough... " If you create or attach a new movie clip on a depth that already has a movie clip, the new or attached clip overwrites the existing content. "
                  • 6. Re: Load library clip into target on stage
                    Karl_Clay_LA Level 1
                    Ahhhhhhhhhh YEEEEEEEESSSSSSSS!!!!!!!!

                    Specifying the level works!!!!!! i.e.

                    on (rollOver) {
                    target.attachMovie("Area1Web1", "anyName", 1);
                    }

                    THANK YOU!!!!!!!