I searched on many forums for an easy implementation of the topic of this little tutorial, the
MovieClipLoader class.
Unfortunately I've been soon discouraged by the really poor piece of information found, so I decided to test some code myself, and after some efforts found out how to implement this really useful object.
Off we go.
First open your swishmax application, and add a new two text objects, call them "bb_text" and "txt_perc", and a new sprite, and call it "gs" (or whatever, the important thing is to mirror these
changes in code).
Movie need to be at least 640*480 for this tutorial to work properly.
Change gs position to x = 0, y = 0 (so that it will be at the top left corner, so perhaps you will have to arrange its anchor point to top left), bb_text at x = 162 and y = 412, and finally txt_perc
x = 463 and y = 439.
We should have something like this:
and
and
As you can see I flaged bb_text to be a target and under Advanced added a variable whose name is "nome", and the same for txt_perc with the variable name "percent".
Well, this done select Scene_1, pass to script tab, and add this code
CODE
onload(){
mcl = new MovieClipLoader();
mcl.onloadInit = function(target){
with(target){
_xscale = 30;
_yscale = 30;
nome = "Complete!"
}
};
gs._x = 40;
gs._y = 150;
mcl.loadClip("http://www.ilgeko.net/kvd/home.swf", this.gs);
}
onEnterFrame(){
percent = gs.percentLoaded();
if ( percent >= 100){
this.onEnterFrame = null; // or delete this.onEnterFrame;
}
}
Some explanations are needed.
First, at onload event, we create a new object of type MovieClipLoader and give it a name "mcl".
We then add a new event method to the newly created instance mcl, onloadInit. This name is important, because this is an abstract method of class
MovieClipLoader, i.e. only its name and signature (number of paramaters and type of paramenters) have been defined by actionscript, but not its implementation.
This means, we can change the body of this method, but not its name!
As for its paramenter, it is optional, but we will use it, as this permit to easily arrange container properties (_xscale and _yscale).
In fact, MovieClipLoader is just a sort of wrapper object to "load" content, but it needs a place where to put loaded data, and in this case, with
CODE
mcl.loadClip("http://www.ilgeko.net/kvd/home.swf", this.gs);
we are loading a swf file (the content) inside our sprite gs (the container).
I know what you now are thinking, this is very like to loadMovie, what's the use of this method over the other?
onloadInit fires only when a content is ready to start, so no more need to write something like
CODE
if (_totalframes == _framesloaded)
and using setInterval to call that code every so many milliseconds...so less code is a big advantage.
The bad news are that I could only run loadClip, unLoadClip and onloadInit methods, all the others for this class are not handled the right way, for example
onloadProgress seems to behave wrongly, and the same getProcess.
So that's why in my example I have used the onEnterFrame event to handle loading progress of sprite gs.
This event fires on entering every frame of my movie, it puts the percentage of loaded bytes into percent variable, and when loading process of sprite "gs" content is over,
exits deleting itself.
You can find an example swi file here
moviecliploader.swi ( 3.34K )
Number of downloads: 2689 or
here for those who cannot download from the attachment

.
I hope this little tutorial cleared some doubts on this useful object.
Cheers
gkaizer