“
By Dave Lally
Okay, for those who have been a little intimidated by some of my lengthier
(read: poignant) tutorials, I’ll throw one at you that’s basic in concept, but one that you can play with if you’re a little more advanced: Loading a JPEG dynamically into Flash. You can keep your SWF file size down by loading your images on the fly rather than imbed them. Plus you can also easily change your image without having to open up Flash at all. First let’s look at the code:
_root.createEmptyMovieClip(”HomerRocks”, 1);
with(HomerRocks){
_x = 35;
_y = 20;
loadMovie(”indian.jpg”);
}
I’ve included the source files again for those who wish to use them. In the first line, we create an empty MovieClip on the root timeline to “hold” our jpeg on the Stage. Within the parenthesis, you name your empty MovieClip with quotes, which, in this case, is HomerRocks. Because he does.
The number following the name assigns the level where you want the empty clip to reside. If you have multiple levels being used in your movie, make sure you don’t assign a level already in use, as only one object can occupy any level at a time. I don’t have anything else going on in this file, so I simply chose level 1.
Next, I’m using the with() statement as a form of shorthand. See, basically, I’m a lazy person, and I don’t want to type:
HomerRocks._x = 35;
HomerRocks._y = 20;
HomerRocks.loadMovie(”indian.jpg”);
Though this does the same thing as the original code, I don’t really want to type “HomerRocks” three times.
Remember, Dave = lazy.
So by using with() and assigning a name of a MovieClip (HomerRocks), any properties or actions I apply in the curly braces will pertain to the named MovieClip. Within the braces of my with() statement, I set the _x and _y positions of my empty MovieClip. When you position an empty MovieClip in this way, remember that you are setting the point for the TOP LEFT corner of your clip. So wherever you assign your clip is where the top left corner of your jpeg will end up. I assigned the _x and _y simply to get it somewhat centered on the stage, and while it is not necessary to do so, I thought I’d show that you can treat your empty MovieClip
like any other MovieClip. You could also assign it a function to move across the stage, or change its rotation or whatever else you can think of.
The last line of the code uses the loadMovie() action to actually call your jpeg from wherever it lies on your server. In quotes, I’ve entered “indian.jpeg.” You would type the URL to your image
you wish to load. That’s all there is to it.
If you want to take it a step further, you could add a preloader component (or make one yourself) and show the progress of your loading jpeg, and have it fade in when it’s done loading. Have fun with it!
“