8 Replies Latest reply on Feb 19, 2010 4:58 PM by Cherie Ann

    Issue loading MC from library in MC Holder

    Cherie Ann

      I searched previous posts last week about this and learned that I can load a movie clip from the library in a blank mc holder similar to how I load an exernal swf. But so far that code is not working for me. I also need a way to close/make invisible the clip on user clicking an X.

       

      I have a page with about 6 key words over which I will place invisible buttons. First button instance is named compworkBtn. I have a blank mc on the stage, name of mcLoadertop. My mc I want to play is in the library and named compworkMC. I read that I need to set the properties to export and I have done this (picture attached for compworkMC).

       

      Here is my action script to load the compworkMC:

       

      //load popups in movie clip loaders top and bottom//
      compworkBtn.onRelease=function(){
      mcLoadertop.attachMovie("compworkMC");
      }

       

      So first I need to get the thing to load.

       

       

      Then I want the user to click on the X or close button and it goes away. I thought the easiest thing for this work be to program the Close button itself to drive the MC to a frame that had no content. It will still be there, of course, but not be visible. Then the user would click on the next key word and the next MC will load. Not sure that is a good solution though, because they will both still be there. So, I'd like a suggestion for another solution to unload the first mc and load the second one. I have done a similar thing with external swfs, but I will need a close button instance for each of the unloads, right?

       

      Any help is appreciated here!SymbolPropertiesMC.jpgCompWorkMC.jpg

        • 1. Re: Issue loading MC from library in MC Holder
          Ned Murphy Adobe Community Professional & MVP

          If you look at the attachMovie() method in the help files they will explain most of what you need to deal with.  The attachMovie method takes a minimum of three arguments..

           

          attachMovie(id:String, name:String, depth:Number)

           

          To remove a movie added using attachMovie you can use the removeMovieClip() method.  That is also explained in the help documents.

           

          As far as assigning functionality to that X button, you can do that after you have attached the movie via using its instance name... something along the lines of... (this is not a verbatum example, just the concept):

          instanceName.btn.onRelease = function(){

               removeMovieClip();

          }

          • 2. Re: Issue loading MC from library in MC Holder
            Cherie Ann Level 1

            Ned,

             

            Ok, my mistake again. I cannot get the programming for the Close button to work. Here's the code I put into the action layer for the button.

             

            closeBtn.onRelease=function(){

                removeMovieClip;

            }

             

             

            Tried it with and without () after MovieClip. Also tried specifying "window" as parameter in Movie clip since that is how it is loaded from the main timeline.

             

             

            1918MC.jpg

             

            I can get this MC to load from a button on the main timeline using the following code. I just can't close it with the button in the MC itself:

             

            on (release) {
            this.attachMovie("1918MC","window",1);
            window._x = 200;
            window._y = 345;
            }

            • 3. Re: Issue loading MC from library in MC Holder
              Ned Murphy Adobe Community Professional & MVP

              Try:

               

              on (release) {
                    this.attachMovie("1918MC","window",1);
                    window._x = 200;
                    window._y = 145;
                    window.closeBtn.onRelease=function(){
                        removeMovieClip(window);
                    }
              }

              • 4. Re: Issue loading MC from library in MC Holder
                Cherie Ann Level 1

                Hi, Ned,

                Thanks for perservering here. I am an e-learning professional, not a programmer, and this is pretty much Greek to me.

                 

                I followed your suggestion and place the code all in the button on the main timeline. But it didn't work. Here's a picture of the code:

                 

                FlashCode.jpg

                 

                When I do that, the 1918 button on the main timeline doesn't even open the MC.

                 

                Here's the code error I get:

                 

                FlashCodeError.jpg

                 

                To me it is logical that the code to use the "close" button in the MC itself should be somewhere in the MC itself, either in the actions layer or in the button itself. Nothing I have tried is working.

                 

                 

                Hope you have another thought. Thanks, again.

                 

                Cherie

                • 5. Re: Issue loading MC from library in MC Holder
                  Ned Murphy Adobe Community Professional & MVP

                  The code does not have to be buried anywhere--generally it's better if it isn't because it is then easier to find.... but the problem with placing code "on()" objects is that it hides it from sight..  You can have it work as I showed it, placing it on the button that you use for the attachMovie.  It will target the button via the movieclip it sits in.

                   

                  If the code you showed earlier actually works to attach the movie from the library, then my code will work as long as you assign an instance name of "closeBtn" to the button inside the movieclip. Instance names are assigned in the properties panel, so if you haven't assigned it, that's what you are missing.

                  1 person found this helpful
                  • 6. Re: Issue loading MC from library in MC Holder
                    Ned Murphy Adobe Community Professional & MVP

                    Here's a link to an example I made using the code I provided and what I believe is the scenario you are trying to realize...

                     

                    http://www.nedwebs.com/Flash/AS2_Attach_Remove.fla

                    • 7. Re: Issue loading MC from library in MC Holder
                      Cherie Ann Level 1

                      Hi, Ned,

                       

                      I finally got it to work. I do know that I need to name the instance when I use the function script and I had named it. Problem is that because I had all these separate little movie clips I had reused the same instance name for each close button. So, I think it wasn't pointed to the right one.

                       

                      I renamed the close button on the 1918mc to close1918Btn, and that did the trick!

                       

                      Thanks for all your help on this one...I was really thinking I would never get this bugger to work. And it is such a SIMPLE thing to make a popup up box appear and disappear already.

                       

                      Cherie

                      • 8. Re: Issue loading MC from library in MC Holder
                        Ned Murphy Adobe Community Professional & MVP

                        You're welcome Cherie

                        1 person found this helpful