Recently I’ve had to use the MovieClipLoader class from AS2, not a fun experience.
What I was trying to achieve was to create a wrapper that loads a swf, then after that swf has finished running load a second swf, then when that had finished run start the first swf again. Simple enough.
If I was doing this in AS3 I could get a lot of information about the child swf being loaded, things like number of frames, current frame, framerate etc. All this information is easy to access by loading the swf using the Loader class then accessing this information through the contentLoaderInfo property of the Loader class.
In AS2 this is not possible, instead I had to use the MovieClipLoader. The way this works is:
- You create a empty MovieClip which is your container to run the loaded swf
- You create a ‘listener’ object that listens for events fired by the MovieClipContainer
- Create listener functions for the common functions that the MovieClipContainer dispatches (onLoadProgress, onLoadInit etc)
- Add the listener object as the listener for the MovieClipContainer
- Finally run the loadClip function to load the external swf
A couple of things I found out using this class, first if you want to get the current or total frames of the loaded swf, its best to do this in the onLoadInit handler, then you can check for this.enterFrame, then use the passed in MovieClip to get the currentFrame, like this
function onLoadInit(_mc:MovieClip)
{
this.onEnterFrame = function()
{
trace(_mc._currentframe);
trace(_mc._totalframes);
};
}
(In AS2 everything starts with a underscore, yuck glad that’s gone in AS3)
Also if you want to add a on click event to the loaded swf you can do this by adding a onPress handler to the onLoadComplete handler, like this:
function onLoadComplete(_mc:MovieClip)
{
_mc.onPress = function()
{
trace(“You clicked me”);
};
}
So while the MovieClipLoader class in AS2 doesn’t have a great deal of functionality through the use of event listener handlers it is possible to do a lot.
Ideally though use AS3, its far easier, gives you more options and insight to what’s happening in the loader.
No comments:
Post a Comment