7 Replies Latest reply on Dec 18, 2006 7:03 AM by Newsgroup_User

    [Q] duplicating movieclip with loaded external jpg file

      Hi, Im trying to make thumbnail and enlarged picture by duplication.
      What i tried was using duplication of thumbnail movieclip which jpg image is loaded
      However it seems not working as i intended,so I had to make empty movieclip and loaded image again!!!


      I am concerning that if I use new movieclip and loading the image again..it means users have to download the same image twice.

      Basically, I am trying to make a list of thumbnailed images with enlarged picture popes up when mouse rolls over them

      Is there any proper way to make it happen?
      or duplication just doesnt work even thou movieclip is already loaded with image?

      Thank you for your time~
        • 1. Re: [Q] duplicating movieclip with loaded external jpg file
          Nixy Level 1
          1- MovieClip have some properties like duplicateMovieClip that disapear when you load something into them. Basicly I can't explain the real reason or all function or properties that does not work after a load, but you found one of them. Here is how you can fix that:

          simple create your movieclip. Now create an empty clip inside. You will load your JPG in the empty clip. This one can't be duplicated, but you will be able to duplicate its parent. Like that:
          myMc.anEmptyClip.loadMovie("blabla.jpg");
          myMc.duplicateMovieClip("theNameYouWant", levelNumYouWant);

          That will works.

          2- Also, the way you where going to do, works too. yes the user will have to load it again, but it is already in the Browser Cache. It means that will load quickly the second time and after that. Bad side is more that you will doble the bandwidth of the images loading on your site.

          3- You ask if there is a proper way to do that, it depends on how you build you application. A simple way sould be to enlarge the movieClip itself when the mouse goes over and reset it to the original size when the mouse out.

          Hope that can help
          • 2. Re: [Q] duplicating movieclip with loaded external jpg file
            Level 7
            > simple create your movieclip. Now create an empty clip inside. You will
            load
            > your JPG in the empty clip. This one can't be duplicated, but you will be
            able
            > to duplicate its parent. Like that:
            > myMc.anEmptyClip.loadMovie("blabla.jpg");
            > myMc.duplicateMovieClip("theNameYouWant", levelNumYouWant);
            >
            > That will works.

            No, that will not work

            You are partly right - if you create a nested clip and assign properties
            (such as an onPress handler) to the parent clip, you can then load content
            into the child without overwriting the parent's properties. If you load an
            image into the child and then duplicate the parent however, the image in the
            child clip *will not be duplicated*. Try it.

            > 2- Also, the way you where going to do, works too. yes the user will have
            to
            > load it again, but it is already in the Browser Cache. It means that will
            load
            > quickly the second time and after that. Bad side is more that you will
            doble
            > the bandwidth of the images loading on your site.

            Again, partly right. Lets take it bit by bit:

            > yes the user will have to
            > load it again, but it is already in the Browser Cache

            The movie will have to load it again, but will probably load it from cache.

            > Bad side is more that you will doble
            > the bandwidth of the images loading on your site.

            Not so. If it's in the cache, it doesn't use any bandwidth at all - that's
            what caching means! A copy of the image is saved on the user's local hard
            drive, so no bandwidth needs to be used when loading from cache.

            Basically, for the *majority* of users, loaded images will be cached (this
            is dependent on browser settings, but most users will have their browsers
            set to cache). This means that after the first load, subsequent loads of the
            same image will be quick and carry no bandwidth overheads.

            The real issue here is that dynamic content in movieClips, such as loaded
            images, swfs, or graphics created with the drawing API will not duplicate
            when the clip is duplicated/ The accepted work around used to be simply to
            reload the aimge. Now with Flash 8 though you can use the BitmapData class
            to grab a copy of the image and redraw it to the newly created clip if you
            so wish.

            Pete
            --
            -------------------------------
            Remove '_spamkiller_' to mail
            -------------------------------


            • 3. Re: [Q] duplicating movieclip with loaded external jpg file
              Nixy Level 1
              Ok, here it is.
              Before I've post a reply, I've test it and my first solution works great!

              This part works:
              ------------------------------------------
              simple create your movieclip. Now create an empty clip inside. You will load your JPG in the empty clip. This one can't be duplicated, but you will be able to duplicate its parent. Like that:
              myMc.anEmptyClip.loadMovie("blabla.jpg");
              myMc.duplicateMovieClip("theNameYouWant", levelNumYouWant);
              ------------------------------------------

              Test it before telling me that does not works please!

              About the second way and the bandwidth, It will works too, but I beleave when you tell that takes the images in the cache, and does not take more bandwidth.
              • 4. Re: [Q] duplicating movieclip with loaded external jpg file
                Level 7
                > Test it before telling me that does not works please!

                lol. Sure, you can duplicate it's parent (or it for that matter), but the
                dynamically loaded image *won't* be duplicated.


                Look - here's an example of it not working:

                //create nested clips and load image:
                this.createEmptyMovieClip("mcImageHolder", this.getNextHighestDepth());
                this.mcImageHolder.createEmptyMovieClip("mcImage",
                this.mcImageHolder.getNextHighestDepth());
                this.mcImageHolder.mcImage.loadMovie("gameMonster_3.jpg");
                // assign onPress handler to onstage button
                btnDuplicate.onPress = function() {
                // duplicate _parent of clip with image...
                duplicateMovieClip("mcImageHolder", "mcImageDup",
                this.getNextHighestDepth());
                // offset new clip...
                mcImageDup._x += 50;
                mcImageDup._y += 50;
                };

                We offset the new clip so that we can see....no duplicated image.

                I've shown you mine, now you show me yours :) I'd love to see an example of
                a dynamically loaded image being duplicated....
                --
                -------------------------------
                Remove '_spamkiller_' to mail
                -------------------------------


                • 5. Re: [Q] duplicating movieclip with loaded external jpg file
                  Peter Lorent Level 2
                  >>I'd love to see an example of a dynamically loaded image being duplicated....
                  Me too. From the help files:
                  If you used MovieClip.loadMovie() or the MovieClipLoader class to load a movie clip, the contents of the SWF file are not duplicated. This means that you cannot save bandwidth by loading a JPEG, GIF, PNG, or SWF file and then duplicating the movie clip.
                  • 6. Re: [Q] duplicating movieclip with loaded external jpg file
                    Nixy Level 1
                    Ok
                    I admit something, I did a basic error. Very basic and stupid error. So, I'm sorry you are right. Here was my basic error, the code to load the image was inside the clip I was duplicating.

                    Well still sorry, and I admit you was right!
                    Stupid Error Code
                    Sometime I need someone to wake me up!

                    • 7. Re: [Q] duplicating movieclip with loaded external jpg file
                      Level 7
                      lol - no problem eh - shame really, for a minute there i thought you'd
                      broken new ground :))



                      --
                      -------------------------------
                      Remove '_spamkiller_' to mail
                      -------------------------------