Part 2:
This is the more complex version.
We are just going to be continuing with your set up from the previous tutorial.
Except in this version, I changed the URLs of the loading images to imageshack URLs so we aren't hot linking ;)
We need to create our loading bar and text now.
So select the rectangle tool and give it whatever stroke and fill color you want. On a new layer, create a fairly long rectangle that looks like a preloader bar. And add some "Loading..." text if you want to make it look fancy. Then select the entire rectangle and text and press F8 to make it a movie clip. Then give it an instance name of
loader_mc. Now go back inside this movie clip and select
only the fill of the rectangle and turn it into a movie clip as well. Then give it an instance name of
bar_mc.
We are now done setting up the preloader component. So go back into the first frame of your actions layer.
New Action Script:
loader_mc._visible = false;
var mcLoader:MovieClipLoader = new MovieClipLoader();
var myListener:Object = new Object();
mcLoader.addListener(myListener);
myListener.onLoadProgress = function(target_mc, bytesLoaded, bytesTotal) {
loader_mc._visible = true;
var pctLoaded = Math.round(bytesLoaded/bytesTotal*100);
loader_mc.bar_mc._xscale = pctLoaded;
if (bytesLoaded >= bytesTotal) {
loader_mc._visible = false;
}
}
mcLoader.loadClip("http://img512.imageshack.us/img512/5727/1419382vx7.jpg", picLoader);
aydy_mc.onRelease = function () {
mcLoader.loadClip("http://img512.imageshack.us/img512/5727/1419382vx7.jpg", picLoader);
}
ftr_mc.onRelease = function () {
mcLoader.loadClip("http://img512.imageshack.us/img512/2429/15357ag0.jpg", picLoader);
}
hcdr_mc.onRelease = function () {
mcLoader.loadClip("http://img512.imageshack.us/img512/1664/165507bz3.jpg", picLoader);
}
h_mc.onRelease = function () {
mcLoader.loadClip("http://img512.imageshack.us/img512/6049/15355rg0.jpg", picLoader);
}
sw_mc.onRelease = function () {
mcLoader.loadClip("http://img512.imageshack.us/img512/3373/15354ax4.jpg", picLoader);
}
loader_mc._visible = false;
Sets the initial visibility property of the
loader_mc movie clip to invisible.
var mcLoader:MovieClipLoader = new MovieClipLoader();
var myListener:Object = new Object();
mcLoader.addListener(myListener);
This creates a new variable and gives it the name of mcLoader. Then we strict type it to a MoveClipLoader and set it equal to a new MovieClipLoader.
Next we create another variable and give it the name myListener. And strict type it to an object. This listener object is not an actual object that will appear on your stage but merely a piece of code that waits for something to happen.
Last, we add the myListener variable to the mcLoader variable.
We have just told the myListener variable to listen for whenever something is being loaded into the mcLoader variable.
myListener.onLoadProgress = function(target_mc, bytesLoaded, bytesTotal) {
loader_mc._visible = true;
var pctLoaded = Math.round(bytesLoaded/bytesTotal*100);
loader_mc.bar_mc._xscale = pctLoaded;
if (bytesLoaded >= bytesTotal) {
loader_mc._visible = false;
}
}
Now we are telling that as soon as something starts to load into the myListener variable, we are going to get the total bytes and the bytes loaded. Then we are going to set the visibility of the
loader_mc movie clip to visible so we can actually see it.
Once the image is 100% loaded then we will make the
loader_mc invisible again.
For details on the rest of this ActionScript, please refer to the
Creating A Preloader tutorial.
mcLoader.loadClip("http://img512.imageshack.us/img512/5727/1419382vx7.jpg", picLoader);
To start out we want our first image to load. So we tell our mcLoader variable to load something. We pass the parameters of the URL for what we want to load and where we want it to load to. We want it to load into our loader component
picLoader.
aydy_mc.onRelease = function () {
mcLoader.loadClip("http://img512.imageshack.us/img512/5727/1419382vx7.jpg", picLoader);
}
ftr_mc.onRelease = function () {
mcLoader.loadClip("http://img512.imageshack.us/img512/2429/15357ag0.jpg", picLoader);
}
hcdr_mc.onRelease = function () {
mcLoader.loadClip("http://img512.imageshack.us/img512/1664/165507bz3.jpg", picLoader);
}
h_mc.onRelease = function () {
mcLoader.loadClip("http://img512.imageshack.us/img512/6049/15355rg0.jpg", picLoader);
}
sw_mc.onRelease = function () {
mcLoader.loadClip("http://img512.imageshack.us/img512/3373/15354ax4.jpg", picLoader);
}
Same thing as above. We are saying that whenever one of the buttons is pushed, we tell our mcLoader variable to load something. We pass the parameters of the URL for what we want to load and where we want it to load to. We want it to load into our loader component
picLoader.
That is all there is to loading pictures dynamically into your flash file and adding a preloader!
dynamicPics2.fla
Thank you for reading this tutorial. I hope you find it very helpful with your flash animations. For any help with this tutorial or questions, please post only in this forum thread.
~Flash Mod