Share Posted January 17, 2012 LoaderMax is great for loading SWF files. However, I want to be able to load a sequence of SWF files with animations in them and loop their playback. I can use loaderMax to load the next SWF at the end of the previous one, but what do I do when I get to the last one? If each SWF was loaded in the container and the container was defined as container:this, does it wipe out the previous SWF? Do I need to unload the last SWF? Is there an unload function? Link to comment Share on other sites More sharing options...
Share Posted January 18, 2012 multiple swfs can share the same container. try giving each swf a unique x or y value and you will see that the swfs will load on top of each other...not replace each other. a quick test: var image:ImageLoader = new ImageLoader("someImage.jpg", {container:this, x:200}); var image2:ImageLoader = new ImageLoader("someImage.jpg", {container:this, x:400}); image.load(); image2.load(); and yes there is an unload() method: http://www.greensock.com/as/docs/tween/ ... ml#unload() image.unload(); but you may not have to use it. you might do fine just setting the visible property of all the swfs except the one you are playing to false. Link to comment Share on other sites More sharing options...
Author Share Posted January 18, 2012 Thanks for the response, but wouldn't that code simultaneously load SWFs? I need to load a SWF, play through it and when it's complete, load the next SWF play it, and continue through 6 SWF files and then play at the start again. If they all get loaded into the same instance (container: this) then I understand I wouldn't need to use unload(). But eventually, I want the administrator to be able to get out of the loop, so an unload() would be necessary then. Link to comment Share on other sites More sharing options...
Share Posted January 18, 2012 the code was provided simply to illustrate that multiple loaders can share the same container. you stated that you had the load-play-load-play sequence already worked out so I didn't see a point in trying to simulate that. sorry if that was unclear. btw if you are interested, you can download an example of multiple swfs loading and playing back-to-back in a looped sequence here: http://www.snorkl.tv/2011/11/snorklreport-big-news/ (scroll to the bottom, click on "download instantly" link) its different than your approach in that all the swfs are loaded completely and then they start playing in order. there might be something in there that helps you though. Link to comment Share on other sites More sharing options...
Author Share Posted January 20, 2012 Awesome! Thanks so much. I'll look into that code sample. Link to comment Share on other sites More sharing options...
Author Share Posted February 7, 2012 OK, the looping is working perfectly. But what if I wanted to create a table of contents and start playing the loop from another choice instead of the first? So, this looks like an Array, but apparently it's not: var swfs:LoaderMax = new LoaderMax({onComplete:completeHandler,onProgress:progressHandler,onChildComplete:childCompleteHandler}); swfs.append(new SWFLoader("hie.swf", {container:container_mc, autoPlay:false})); swfs.append(new SWFLoader("rhapsody.swf", {container:container_mc, autoPlay:false})); swfs.append(new SWFLoader("conclusion.swf", {container:container_mc, autoPlay:false})); So when I call on swfs.load(); to start the looping, I thought I could pass in a position to start, but it's not possible. I thought the loaderIndex could be incremented, but it doesn't work. Any suggestions? Link to comment Share on other sites More sharing options...
Share Posted February 7, 2012 Hi, LoaderMax's getChildAt() method will allow you to retrieve loaders based on their index in the LoaderMax. http://www.greensock.com/as/docs/tween/ ... etChildAt() i think that should help. c Link to comment Share on other sites More sharing options...
Author Share Posted February 9, 2012 Sorry, that really didn't help. With the code I have, it's not like I can set the index of the loader to something other than the order that the queue is set to. At least I don't know how to do it. Every time I call swfs.load() it starts from the beginning of the queue. I want to be able to start from any point in the queue. var swfs:LoaderMax = new LoaderMax({onComplete:completeHandler,onProgress:progressHandler,onChildComplete:childCompleteHandler}); swfs.append(new SWFLoader("hie.swf", {container:container_mc, autoPlay:false})); swfs.append(new SWFLoader("rhapsody.swf", {container:container_mc, autoPlay:false})); swfs.append(new SWFLoader("conclusion.swf", {container:container_mc, autoPlay:false})); function progressHandler(e:LoaderEvent):void { trace(e.target.progress); } function childCompleteHandler(e:LoaderEvent):void { trace(e.target + " loaded"); e.target.content.visible = false; } function completeHandler(e:LoaderEvent):void { trace("all swfs loaded"); // progress_mc.visible = false; initCurrentLoader(); addEventListener(Event.ENTER_FRAME, trackSWFPlayback); } function initCurrentLoader() { loaderIndex++; if (loaderIndex == swfs.numChildren) { //reset back to 0 if the last swf has already played loaderIndex = 0; } //dynamically reference current loader based on value of loaderIndex currentLoader = swfs.getChildAt(loaderIndex); //make the content of the current loader visible currentLoader.content.visible = true; //tell the current loader's swf to to play currentLoader.rawContent.gotoAndPlay(1); } function trackSWFPlayback(e:Event):void { //trace(currentLoader.rawContent.currentFrame); //detect if the loaded swf is on the last frame if (currentLoader.rawContent.currentFrame == currentLoader.rawContent.totalFrames) { trace("swf done"); //hide and stop current swf currentLoader.content.visible = false; currentLoader.rawContent.stop(); //set up and play the next swf initCurrentLoader(); } } playall_btn.addEventListener(MouseEvent.CLICK, loadSWFs); function loadSWFs(e:MouseEvent):void{ // load_btn.visible = false; swfs.load(); } Link to comment Share on other sites More sharing options...
Share Posted February 9, 2012 the system you are using is built specifically to load all the assets upfront so that they can seamlessly play in succession (without any load inbetween). if you want to jump to a specific loader (without preloading them all first) you can do something like: currentLoader = swfs.getChildAt(loaderIndex); currentLoader.load(); if you want to have non-linear navigation (jump to any swf at any time) you are going to have to rework the code you have a fair bit in order to make to maintain the features of the sequencing. you will have to be sure to set the visible property of the requested swf to true and be sure to hide any currently visible swfs. if you load the loader at index of 5 in your LoaderMax, you will also have to manually set the loaderIndex var to 5 Link to comment Share on other sites More sharing options...
Author Share Posted February 9, 2012 Yeah, I figured it wouldn't be that easy. The client wants both functionality though - looping playback and then a table of contents to start from any chapter. Thanks. Link to comment Share on other sites More sharing options...
Share Posted April 18, 2012 Did you ever get this working? I have a similar problem. Link to comment Share on other sites More sharing options...
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