Hanti Posted June 15, 2013 Posted June 15, 2013 Hi people! Help me please! I have this package code for a section menù. I have on the stage 4 menù item (name:swf1,swf2,swf3,swf4) and have one progress bar (name:progress_mc). I have in the folder "swf" 4 swf (name:swf1,swf2,swf3,swf4). I start with load swf and then when I click on one of the buttons load the swf corresponding (by the istance name). I would like to implement this code whit LoaderMax for load/unload this external swf and mark the progress bar. But I can not do! someone can help me? Tnx! package { import flash.events.MouseEvent; import flash.net.URLRequest; import flash.display.*; import flash.events.Event; public class caricaredatiesterni extends MovieClip { var defaultSWF:URLRequest = new URLRequest("swf/swf1.swf"); var loader:Loader = new Loader(); public function caricaredatiesterni() { var swf=new Array(swf1,swf2,swf3,swf4) for(var i:int=0; i<swf.length; i++) { swf.addEventListener(MouseEvent.CLICK, openSwf); } loader.load(defaultSWF); addChild(loader); } public function openSwf(e:MouseEvent) { removeChild(loader); var newSWFRequest:URLRequest = new URLRequest("swf/" + e.target.name + ".swf"); loader.load(newSWFRequest); addChild(loader); } } }
Carl Posted June 15, 2013 Posted June 15, 2013 Hi and welcome to the GreenSock forums. Using SWFLoader in that setup is fairly straightforward import com.greensock.*; import com.greensock.loading.SWFLoader; import com.greensock.events.LoaderEvent; import flash.events.MouseEvent; var loader:SWFLoader = new SWFLoader("swf1.swf",{container:this}); var swf = new Array(swf1,swf2); for (var i:int=0; i<swf.length; i++) { swf[i].addEventListener(MouseEvent.CLICK, openSwf); } function openSwf(e:MouseEvent): void{ var newURL:String = e.target.name + ".swf"; loader.url = newURL loader.load(true); // reload SWFLoader and flush/unload old content } //load the first swf loader.load(); Be sure to check out the SWFLoader docs: http://api.greensock.com/as/com/greensock/loading/SWFLoader.html CS5 files attached loadSwf2Swf2_CS5.zip 1
Hanti Posted June 17, 2013 Author Posted June 17, 2013 Hi Carl! Thank for your reply! I implement your code with the progress bar, is correct? Or you could do better? I'm a student and I would like to learn to use loaderMax for loading a site section (by external swf). import com.greensock.*; import com.greensock.loading.SWFLoader; import com.greensock.events.LoaderEvent; import flash.events.MouseEvent; var loader:SWFLoader = new SWFLoader("swf1.swf",{onInit:initHandler, onProgress:progressHandler, onComplete:completeHandler, container:this}); var swf = new Array(swf1,swf2); for (var i:int=0; i<swf.length; i++) { swf[i].addEventListener(MouseEvent.CLICK, openSwf); } function openSwf(e:MouseEvent): void{ var newURL:String = e.target.name + ".swf"; loader.url = newURL loader.load(true); // reload SWFLoader and flush/unload old content } function initHandler(event:LoaderEvent):void { //fade the swf in as soon as it inits TweenLite.from(event.target.content, 1, {alpha:0}); } function progressHandler(event:LoaderEvent):void { progress_mc.progressBar_mc.scaleX = event.target.progress; trace("progress: " + event.target.progress); } function completeHandler(event:LoaderEvent):void { trace(event.target + " is complete!"); TweenLite.to(progress_mc.progressBar_mc, 1, {alpha:0}); } //load the first swf loader.load(); I would have some question: - In LoaderMax is not necessary flush/unload old swf with removeChild? - How i can to do convey the estimatedBytes for each swf? - This is the right way to work for load a different section of my site? Thank you so much!
Carl Posted June 17, 2013 Posted June 17, 2013 In LoaderMax is not necessary flush/unload old swf with removeChild? removeChild only removes the object from the display list. Sometimes that is enough. If your swfs are big and possibly have processes still running in them after you hide them, I would suggest flushing them. There isn't a cut an dry answer. How i can to do convey the estimatedBytes for each swf? Not sure what you mean, each SWFLoader has a bytesLoaded and bytesTotal properties. This is the right way to work for load a different section of my site? Sure, this can work fine. I'd probably create 4 or 5 SWFLoaders and add them to a LoaderMax queue, or even use XMLLoader (which is more advanced). You can read more about these techniques here: http://www.snorkl.tv/2011/08/loading-images-with-loadermax-load-and-track-the-progress-of-multiple-images/ http://www.snorkl.tv/2011/08/loading-images-with-loadermax-part-2-the-xmlloader/ Even thought those tutorials focus on ImageLoaders, the same concepts apply to any loader type.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now