18 Replies Latest reply on Oct 7, 2007 11:29 PM by

    Preloading 2nd movie while 1st plays

      I have two movies, Animation01.swf (30K) and animation02.swf (2MB). Additionally, I have a preloader movie, preloader.swf.

      What I am trying to do is from the preloader.swf is to load the first move (Animation01) and as soon as it finishes loading, to play it. While Animation01 is playing, I'm trying to preload Animation02 in the background. Animation02 must only begin playing after the first one finishes.

      On the first frame of Animation01 and Animation02 I have a boolean variable donePlaying set to false. On the last frame of each animation I set the donePlaying variable to true so I can access it from the preloader. I am doing this (incorrectly?) to know if the current movie has finished playing so I can start playing the second one.

      I have searched high-and low and have seen discussions on what is almost the same problem/solution. From these discussions I have created the code below. What is happening right now is that I can't seem to call moviesLoaded[0].play()... Meaning that nothing plays. If I remove the targetMc.stop() from inside the onLoadComplete event handler, then both movies play right away atop each other :(

        • 1. Re: Preloading 2nd movie while 1st plays
          kglad Adobe Community Professional & MVP
          at the end of Animation01 check if animation02 has completed loading. if so, start its play. if not, assign a boolean variable to true so in animation02's onLoadInit (not onLoadComplete) method if starts play.
          • 2. Re: Preloading 2nd movie while 1st plays
            Hi, kglad! Thanks for your input. Let's see if I get this straight. In addition to the variable in each of the two movies, I can add one more ("doneLoading"). I set this to true in the onLoadInit event handler. Then I play the first movie straight out. For the second movie, I test whether it's done loading and the first movie done playing before running it.

            I'm going to try it now. I'll post back my results.
            • 3. Re: Preloading 2nd movie while 1st plays
              kglad Adobe Community Professional & MVP
              you don't anything in addition to what i described. basically, one of those two events will occur last: either animation01 completes play last (and animation02 is ready to go) or animation02 loads last and is ready to play.
              1 person found this helpful
              • 4. Preloading 2nd movie while 1st plays
                Kglad, your suggestion did not work (or I still didn't understand you.)

                Ok, my deadline is tomorrow (it's 2am now)... ouch. One thing I realized is that the previous code I posted is needlessly complex, as it takes an arbitrary number of movies to preload. This is dumb because I only want to preload two movies. So, I tried simplifying it a bit. Following is the logical concept of the movies I have:

                preloader.swf
                |___FrontEnd-Ext-v16.swf (first movie to preload)
                |
                |___Mesozoic_Animation-v32.swf (second movie to preload)


                Now it seems I have two problems. My handlers are not getting called on the INIT event of the Loaders. Also I can't seem to access the Loader.content so I can do something like mcLoaderOne.content.stop(). Some one, kindly tell me where in my code I'm making the mistake(s).

                FYI - This is pertaining to ActionScript 3. My goal is to preload one move then play it automatically. While the first move plays, the second movie will be preloaded into cache. When the first movie finishes playing and the second movie is done loading, then play the second movie. Here's the new code I've written.

                • 5. Preloading 2nd movie while 1st plays
                  Just noticed the typo on the argument names of both event handlers. I've corrected this but I am still in the same boat. The first movie loads but I can't see it. I know it is loading because I can hear its sound track. The second movie doesn't load at all, of course. :(

                  Some one please help or put me out of my misery. lol
                  • 6. Re: Preloading 2nd movie while 1st plays
                    kglad Adobe Community Professional & MVP
                    that's not going to work. there are many problems with the logic.

                    when animation02 is done loading check if animation01 is done playing (ie, put mcLoaderOne.content.currentFrame == mcLoaderOne.content.totalFrames in your onInitTwo() function) . if yes, remove animation01 and start animation02.

                    if no, either start a loop to check when animation01 completes play (and then remove animation01 and start animation02) or dispatch an event when animation01 completes play and in that event handler check if animation02 has completed loading (if yes, remove animation01 and start animation02; if no, then the code described in the first paragraph will trigger the events you want.)
                    • 7. Re: Preloading 2nd movie while 1st plays
                      Hey, Kglad -- You remind me a lot of my martial arts teacher in the way you explain things. lol

                      I understand what I need to do, according to your posting. There's still one issue my friend and that is the first movie is loading (but not displaying) yet my first init handler is not getting called. Can you, or any one else, tell my why this is?

                      Thank you so much for your assistance. I've seen so many questions on this topic that I want to post the final working code so we are just a little bit more enlightened. :D
                      • 8. Re: Preloading 2nd movie while 1st plays
                        kglad Adobe Community Professional & MVP
                        the init event occurs when loading is complete and all the methods and properties of the loading file are available.

                        the open event occurs when loading starts.
                        • 9. Preloading 2nd movie while 1st plays
                          Hi again -- Ok, I get it that INIT event triggers when the movie is done loading, COMPLETE when the loaded movie's playhead is finished with the last frame. Thing is that I know the first movie is being loaded (have a trace call from within and see it in output fine.) However, the INIT handler is not getting triggered nor the COMPLETE event. Further, I can't seem to access the movie which has been loaded (example, mcLoaderOne.content.gotoAndPlay(2)).

                          If I can get the events to trigger the handlers for the first movie, I can figure out the rest. Same with being able to send messages to the loaded movie.

                          Here's how I've modified the events and handlers:

                          • 10. Re: Preloading 2nd movie while 1st plays
                            kglad Adobe Community Professional & MVP
                            oh, the loader class doesn't have those events. the loader's contentLoaderInfo property has those events.
                            • 11. Re: Preloading 2nd movie while 1st plays
                              Kglad -- Totally makes sense and the events are now triggering correctly. For every one's benefit, below is the working code.

                              One thing I noticed is the COMPLETE event is not what is triggered once the movie finishes playing. It triggers immediately right after the INIT event is fired. Lastly is that I still can't seem to talk to my loaded movie with mcLoader.content.gotoAndPlay(2)



                              • 12. Preloading 2nd movie while 1st plays
                                Darn, obviously the code example should not have the bold tags tags... :S
                                • 13. Re: Preloading 2nd movie while 1st plays
                                  kglad Adobe Community Professional & MVP
                                  are you executing your mcLoader.content.gotoAndPlay(2) statement in one of the oncomplete or oninit functions?
                                  1 person found this helpful
                                  • 14. Re: Preloading 2nd movie while 1st plays
                                    Hi, Kglad,

                                    Man, I feel like I've come a long way since my first posting, thanks to you and some heavy googling + experimenting. Here's the status of things, as I've modified the code a lot. Good news is that I can get the first movie loaded and start playing. I can get the second movie to start loading also. Further, I can also track when the first movie finishes playing and add the second movie. The only thing remaining is getting the second movie to play.

                                    Here's my code. Although certain things could be coded better, I feel 95% of it works now. Kglad, I commented the two parts that seem not to be working.

                                    • 15. Re: Preloading 2nd movie while 1st plays
                                      kglad Adobe Community Professional & MVP
                                      i'd say that's a bit much. it was easier to write the code than to debug your code:

                                      • 16. Re: Preloading 2nd movie while 1st plays
                                        Hahaha... you're so right, kglad. Your code is much more concise. Let me try it out and will post in a bit.

                                        Thanks again for all your support.
                                        • 17. Re: Preloading 2nd movie while 1st plays
                                          kglad Adobe Community Professional & MVP
                                          you're welcome.
                                          1 person found this helpful
                                          • 18. Re: Preloading 2nd movie while 1st plays
                                            Kglad, just wanted to thank you for your consistent assistance. Your code worked very well. I only added the this.addChild() where needed for both Loader instances. I'm going to check out your site too, dude.

                                            Have a great day.