3 Replies Latest reply on Dec 1, 2009 6:02 PM by kglad

    Loading into the library at runtime?

    wdb88

      I have built a flash animation (for a web site) that requires a number of decent quality JPG images.  I don't display all of these at the start, so I don't want to wait for them all to load before starting the animation.  Thus I want to be able to load these images in the background - the obvious process would involve MovieClipLoader.loadClip() method.  This works fine if I am loading into an INSTANCE of a moveclip (either existing on the stage or one that I creat in actionscript) - but I really want to load into a library movieclip.

       

      The problem is that I end up using these images in two different movies on the stage - each pulls from a movieclip in the library (that contains the image I want).  So my original thought was simply to load (using loadClip()) into the library movie - which in turn would show up in the two stage movieclips that have this library clip in the timeline.  However, I cannot seem to get loadClip() to work with a library object.

       

      I tried exporting the library movieclip to actionscript (giving it a name) - but loadClip() doesn't seem to want to load into it.  I can only get loadClip() to load into an instance that exists on the stage.

       

      Sorry if I am asking a stupid question - I don't do a lot of flash programming - although I have extensive programming experience in other languages.

       

      So can this be done?  Is there another way to accomplish what I want to do?

       

      I can easily load into an instance of a movieclip - but I don't want to load each image twice (into two different movieclips that I need to manipulate) - hence my desire to load into a single library object that end up having multiple instances on the stage.

       

      My other thought was to load into an instance and then COPY that instance to the second instance.  But I can't seem to find a way to copy one clip into another clip?

       

      Any pointers would be very much appreciated.

       

      Just to clarify, here is an example.

       

      *  I have several library movieclips (call them clip1, clip2, clip3... )  which contain a single frame with a JPG image in that frame.

       

      * I have a library movieclip called bkgnd which has 10 frames in it.  Each frame has an instance of the different clips above (e.g. frame 1 has clip1 in it, frame 2 has clip2 in it, frame 3 has clip3 in it etc).  At run time, this move is manipulated through gotoAndStop() to display a particular image.

       

      * I use this bkgnd library movieclip in TWO places on the real stage (two instances).  Each is controlled through actionscript to display particular frames (particular images) through the gotoAndStop() method.

       

      * I want to be able to load the individual images at runtime - my thought was to use loadClip() to load JPG files into the clip1, clip2, clip3... library clips.  However, loadClip() doesn't seem to want to load into a library clip.

        • 1. Re: Loading into the library at runtime?
          kglad Adobe Community Professional & MVP

          you can't load into the library or into a library movieclip.  objects in your fla library don't exist in your swf unless they're instantiated.

           

          you can load twice (and, if you wait until loading is complete with the first load, the 2nd will be retrieved from the user's cache and not downloaded) or, you can use the bitmapdata class'es draw() method to copy the first loaded image and duplicate it.

          • 2. Re: Loading into the library at runtime?
            wdb88 Level 1

            Thank you.  I was able to use the bitmap class draw function to accomplish what I wanted.

             

            It got pretty convoluted though.  Used actionscript on instances of hidden movies to initiate the loading.

            Had a loader bar on images when they are used - but wanted them to load asynchronously in the background (use the first while others are loading).

             

            There are lots of little "gotchas" with this stuff, and while flash is very powerful, it is difficult to document / take apart.  Because action script is all over the place and interacts in very funny ways, it can be very complicated to figure out how all the timelines mesh and what code is running when.

             

            I have to say I am quite disappointed in a few items - one of which is that if you associate actionscript with a particular item on the stage (a movie clip), you don't see it highlighted in the timeline and you don't see it on the movie inspector.  It is kind of hidden out there unless you know to look for it.

             

            Anyway - thanks again.  Definitely did the trick..... Warren

            • 3. Re: Loading into the library at runtime?
              kglad Adobe Community Professional & MVP

              you're welcome.

               

              actionscript 2.0 grew and evolved into a messy language with lots of gotchas.  a.s. 3.0 is much more consistant.