One loader screen with several .fla
I've got loader screen in one .fla and several other .fla files that should use it. How can I use this one loader with all other files? 开发者_如何学Python thank you.
Not sure why you are getting downvoted, this is a pretty standard question in Flash-land.
Basically, the .swf that gets published by your preloader .fla needs to be able to load in and then display the .swf's published by your other .fla's. You would put code that looks like this into your preloader:
var swf1:MovieClip;
var swf2:MovieClip;
function loadFirstSwf():void {
var loader:Loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, firstSWFLoaded);
loader.load( new URLRequest( "swf1.swf" ));
}
function firstSWFLoaded(e:Event):void {
swf1 = MovieClip(e.currentTarget.content);
e.currentTarget.removeEventListener(Event.COMPLETE, firstSWFLoaded);
loadSecondSwf();
}
function loadSecondSwf():void {
var loader:Loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, secondSWFLoaded);
loader.load( new URLRequest( "swf2.swf" ));
}
function secondSWFLoaded(e:Event):void {
swf2 = MovieClip(e.currentTarget.content);
e.currentTarget.removeEventListener(Event.COMPLETE, secondSWFLoaded);
whatever();
}
function whatever():void {
// logic here to do whatever you need to do next.
}
loadFirstSwf();
Note that this isn't the most efficient architecture - I tried to keep it as simple as possible, not being sure of your level of AS3 experience. A few things to note:
1) You're calling these sequentially. When the first one finishes, it gets the second one, etc. You can add a third and fourth and etc. This is to make explicit the order in which they arrive. You can also fire them all at once, but it requires some additional logic to make sure you know what's coming from where because they can finish in different order than you start them. This is a common rookie mistake and I'm trying to set it up so that you don't have to deal with it.
2) You're making sure that you remove the event listeners from your loaders after you extract the loaded .swf. This just makes sure that they don't hang around in memory forever.
3) You're not actually listening for progress using this example - if you'd like to, you can use loader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, progressHandler) and then put code in your progress handler to listen for the actual current state of the load.
So, the example above is super simple but should work. If you want to get something more robust, or if you're dealing with a lot of child swf's, look into using something like LoaderMax from GreenSock - that's a free third-party library that helps you manage the loading of multiple files easily.
Cheers and I hope that helps!
精彩评论