8 Replies Latest reply on Aug 24, 2006 8:09 PM by Rothrock

    Load JPEG?

      I want my Flash piece to load JPEGs at runtime. I thought Flash MX 2004 had this functionality, but searching "load image" or "load JPEG" has resulted in nothing. Is this possible? If so, what's the command?
        • 1. Re: Load JPEG?
          paulpsd7 Level 1
          I found the answer. The command loadMovie handles the loading of both SWFs and JPGs. (I thought it was just SWFs.)
          • 2. Re: Load JPEG?
            Rothrock Level 5
            Flash MX04 has a much better choice for this (and for SWFs as well). Look at the MovieClipLoader class. The nice part about it is that you have the ability to define event handlers to do things like onLoadProgress() and onLoadInit(). With the loadMovie approach you will need to define your own code to handle preloading and such. That is a great thing to know, but MCL is pretty easy.

            Also be careful. Under Flash MX04 you can't load progressive JPEGs. (I think they changed that under Flash 8.) So if it all seems like it should be working and yet you aren't seeing the pictures…
            • 3. Re: Load JPEG?
              paulpsd7 Level 1
              Brilliant. Thanks so much for the tips. I think I'll use MovieClipLoader just for those event handlers.

              Fortunately, I didn't save any of my JPGs in progressive mode, so I'm safe! Thanks again.
              • 4. Re: Load JPEG?
                Rothrock Level 5
                Good luck! You would be surprised how often folks who are having problems seem to believe that they didn't save any progressive jpegs! Just file it away for that day when it all goes wrong. :)
                • 5. Re: Load JPEG?
                  paulpsd7 Level 1
                  OK, I'm running into the exact problem you described! However, I've resaved my JPEGs once again from ImageReady, and I'm certain that they are not saved as progressive. (That is, in the Optimize window, the progressive checkbox is unchecked.)

                  In a nutshell, I'm duplicating a movie clip (predes.thumb), and then loading a different JPG into a movie clip nested in the one I'm duplicating (predes.thumb.thumb_image). I'm also adding some data to each movie clip to govern how it functions.

                  For this one, I'm using loadMovie instead of MovieClipLoader, since I don't need those extra event handlers for this bit. (I'm using MovieClipLoader elsewhere.)

                  Here's the code:

                  for (itr = 0; itr < predesigned.filename.length; itr++) {
                  duplicateMovieClip (this.predes.thumb, "thumb" + itr, itr );
                  loadMovie (eval ("thumbs/" + predesigned.filename[itr] + ".jpg"), this.predes.thumb[itr].thumb_image);
                  eval ("this.predes.thumb" + itr)._y = 20 + (75 * itr);
                  eval ("this.predes.thumb" + itr).myURL = predesigned.siteurl[itr];
                  eval ("this.predes.thumb" + itr).myName = predesigned.designname[itr];
                  eval ("this.predes.thumb" + itr).myFile = predesigned.filename[itr];

                  Through trace commands, I've determined that everything is working apart from loading in the JPEGs.

                  Do you think there might be some incompatibility between Flash and ImageReady's JPEGs?

                  Anything else you can think of?
                  • 6. Re: Load JPEG?
                    Rothrock Level 5
                    What happens if you just have a clip, either from the authoring environment or using this.createEmptyMovieClip("Newname",100)? Can you load the image into that. If so, then the problem is with your code. If not there might be something strange with the image.

                    And speaking of your code…How can I put this nicely – your code is insane. :) Not really that bad, just old style and I find it quite difficult to follow what is going on here. So lets start with it line by line.

                    the for line is great. You might want to rewrite it like this:

                    for(var itr=0;itr<predesigned.filename.length; itr++){

                    The var prefix there will help keep the variable local to the for loop. Okay the next line. Let's use the duplicate method of the movieclip class. It has a swee benefit that the global method you are using doesn't have. So this line will become:

                    var curClip=this.predes.thumb.duplicateMovieClip("thumb"+itr,1000+itr);

                    This way you can assign a reference to the newly duplicated clip. This way you can reference it later with curClip instead of having to use the crazy eval stuff. Did I mention that I never use eval? That it would most likely be the problem – well except the next line, but I get ahead of myself. I got one more problem with the duplicate line. When assigning, creating, etc. clips it is better to use positive depths. With your code the first clip would be at a depth of zero. This could cause problem latter. You do have millions of depths, so use them.

                    I was having a hard time reading the next line because, again, you are using the old style global method. At first I didn't realize what clip you were loading into, but now I see it is there. I would update this line to:


                    No eval is needed for the jpg file. Also you are sure that the clip you are duplicating does have a thumb_image clip inside it, right?

                    All the next lines could be updated and made easier in two different ways. The first is to just use the variable we assigned earlier.


                    Or you could use the array notation. LIke this.


                    The array notation is much cleaner, at least to my eye and it lets you so easily combine static things and variables.

                    • 7. Re: Load JPEG?
                      paulpsd7 Level 1
                      Woo hoo!!

                      Thanks so much for disecting my code and setting it straight. Seriously, insult my code all you like. I don't really consider myself a programmer, and I learned much of my actionscript in versions 4-6, so I know I'm not using the most efficient methods. I learned tons from your code, and best of all, everything works!!! Thanks again!
                      • 8. Re: Load JPEG?
                        Rothrock Level 5
                        Glad you took that in the spirit it was intended. And really glad that worked out for you.