3 Replies Latest reply on May 7, 2009 4:53 PM by Ned Murphy

    Newbie add Movieclip problem

    JonnyDL-HV74P1

      I have been hunting over the web trying to figure out how to create a movielclip, and then put an external file into it (picture or swf)

      In my hunt I've confused myself. and I'm hoping to get some guidence clarity (and hopefully help someone else out).

       

      I first need to create the movieclip

      var holder_mc:MovieClip = new MovieClip;

       

      next I defined where the file is

      filelocal = "somegalaxy/far/far/away"

       

      this is where I hit the wall, I seen examples where I need to add a listener , others just looked like they added the child.

      I went the simple (wrong) route and tried just using the addChild. Complied, but nothing

       

      addChild.holder_mc (filelocal).

       

      I was trying to use the kiss principle "keep it simple stupid" so I can understand the conceptes and grow from there, but I can see I need more code (to figure out what it dose) to get it to work.

       

       

      Any help is appreciated.

        • 1. Re: Newbie add Movieclip problem
          Ned Murphy Adobe Community Professional & MVP

          I'm assuming you're working with AS2, but your post looks like you got AS3 in the mix.  If you look up MovieClipLoader.addListener function in the Flash help documents, the example(s) there may be all you need to get thru this.

          • 2. Re: Newbie add Movieclip problem
            JonnyDL-HV74P1 Level 1

            Once again (Ned) you were a help, but I was hoping for a bit of clarity

            I copied some code and understand most of it but I was hoping you code give a little more clarification

             

            -----self explaintory (though why do you need to create an emptyclip, just to create a new one later?)

            this.createEmptyMovieClip("fileImport_mc",2);

             

             

            ----not sure what this is doing creating a listener object? (having a hard time understanding this concept)

             

            var mclListener:Object = new Object();

            mclListener.onLoadInit = function(target_mc:MovieClip)

            {

            target_mc._x = 0

            target_mc._y = 0


            };

            --creates a new movieclip (back to the top, didn't i make a make one/)

            var image_mcl:MovieClipLoader = new MovieClipLoader();

             

            --- Understanding it calling the listener function, for the Movieclip object, just still unclear on the listener

            image_mcl.addListener(mclListener);

             

            ----gets the movie clip instance uses the files locations, and loads it into the movie clip(loader)

            image_mcl.loadClip("files location", fileImport_mc);

             

            any clarfication you can give (or anyone else wants to contribute) is greatfully appreciated. Hopefully any clafication will help me, and make it easier for the next newbie who has a simular promblem.

             

            Thanks

            • 3. Re: Newbie add Movieclip problem
              Ned Murphy Adobe Community Professional & MVP

              why do you need to create an emptyclip, just to create a new one later?

               

              this.createEmptyMovieClip("fileImport_mc",2);

               

              What happens is, you create the empty one and the loaded one replaces it.  You can target the loaded movie by the instance name you assigned to the created one.

               

              ----

               

               

               

              var mclListener:Object = new Object();

               

              That line creates a listener object... it's ready to go to work for you for any type of object that supports having a listener.  It is used to check events relative to the object

               

              Below is an event handler function designated for the listener... often people will utilize the onLoadComplete event rather than the onLoadInit.  You can read all about the events supported in the help files

               

              mclListener.onLoadInit = function(target_mc:MovieClip)

              {

              do stuff that needs to be done after the event is complete

              };

               

              -------

               

              var image_mcl:MovieClipLoader = new MovieClipLoader();

               

              That line isn't creating another movieclip... it's creating a MovieClipLoader instance, the vehicle that will be used for loading the swf or image file.  And the next line is assigning the listener to that loader so that you'll be able to tell when something relative to the loading has transpired.

               

               

               

              image_mcl.addListener(mclListener);

               

              So the last line puts the loader, which is armed with a listener and a target for the loaded item, into action

               

               

              image_mcl.loadClip("files location", fileImport_mc);

               

              While they can often be a challenge to deal with and interpret, eventually you get the hang of them, and the help documentation become a very handy ally in the war to conquer Flash.  If you ever have a need to understand, a bit of reading is always helpful... beats having me trying to explain it.  The AS3 documentation is a bit easier to work with though.