21 Replies Latest reply on Jun 28, 2007 9:38 PM by kglad

    stopping an external swf

    jorisbleys
      Hi all,

      I'm trying to load a .swf file in the background, but the problem is the movie starts before I instruct it to and I don't know how to stop it. I've written a preloader before using the same code but it didn't have the same problem.

      Any advice is welcome!

      Best,

      Joris

      var finaleMovieLoaded:Boolean = false;
      var finaleMovieLoader:Loader = new Loader();
      var finaleMovieFileName:URLRequest = new URLRequest("stad.swf");

      function showFinaleProgress(evt:ProgressEvent):void
      {
      trace(evt.bytesLoaded/evt.bytesTotal);
      }

      function showFinaleLoadResult(evt:Event):void {
      finaleMovieLoaded = true;
      trace('loading finale completed');
      }

      function showFinaleMovie(event:Event):void
      {
      trace('starting finale');
      addChild(finaleMovieLoader);
      }

      // link functions to the events related to loading the finale movie
      finaleMovieLoader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS,showFinaleProg ress);
      finaleMovieLoader.contentLoaderInfo.addEventListener(Event.COMPLETE,showFinaleLoadResult);
      finalebtn.addEventListener(MouseEvent.CLICK, showFinaleMovie);

      // start loading the main movie
      finaleMovieLoader.load(finaleMovieFileName);
        • 1. Re: stopping an external swf
          jorisbleys Level 1
          Sorry for the double post ... Please ignore this thread! I don't know how to remove it myself!
          • 2. Re: stopping an external swf
            kglad Adobe Community Professional & MVP
            don't add your loader to the display list until you want it to start.
            • 3. Re: stopping an external swf
              jorisbleys Level 1
              Hi kglad,

              Thanks for the hint, but could you elaborate a bit on how I could achieve that?

              I'm only using addChild() in a function which should be called after user has clicked on a button.

              Best,

              Joris
              • 4. Re: stopping an external swf
                SymTsb Level 2
                Make it so that the addChild is done when the movie is completely loaded not when the user clicks the button. The button should load your movie and the complete handler should add it to the display list.
                • 5. Re: stopping an external swf
                  jorisbleys Level 1
                  Hi SymTsb,

                  Thanks for you answer and indeed this could work. The problem however is that the .swf that is loaded is quite big (a few megabytes) and I would like to circumvent the waiting time by loading it in the background.

                  My main problem I guess is that I can not access the actual MovieClip inside the instance of Loader. If only I could get a handle on it so I could call the appropriate .start() and .stop() methods ...

                  Best,

                  Joris
                  • 6. Re: stopping an external swf
                    kglad Adobe Community Professional & MVP
                    then load it. just don't add it to the display list with addChild(finaleMovieLoader) until you want it to start.

                    you can reference your loaded swf's main timeline by using the content property of your loader and casting it as a movieclip:

                    • 7. Re: stopping an external swf
                      jorisbleys Level 1
                      Hi kglad,

                      Thanks for the hint! Indeed, downcasting to the MovieClip class of the contents property of the Loader was the key to getting the behaviour I wanted.

                      I still don't get it why the child is added as it is in a function which is only called on a click event. Circumvented this by stopping the 'stad.swf' file in the first frame and playing it by moving the head to frame 2.

                      I'm marking your answer as the solution to this question.

                      Thanks a lot!

                      Joris
                      • 8. Re: stopping an external swf
                        kglad Adobe Community Professional & MVP
                        you're welcome.
                        • 9. Re: stopping an external swf
                          xnomadx
                          Hello

                          I am having the exact same problem as jorisbleys and I am very curious how you got this to work. Can someone possibly show how the MovieClip(finaleMovieLoader.content).stop() actually looks in the code? It would be very much appreciated!
                          • 10. Re: stopping an external swf
                            kglad Adobe Community Professional & MVP
                            that's how it looks. i know it looks peculiar but that's the way it is.
                            • 11. stopping an external swf
                              xnomadx Level 1
                              kglad-

                              Thanks for your reply! Especially on my first post, I feel lucky.I should have went into more detail. I have a large Flex 2 application swf that I am loading in the background during the "preloader" the code is much the same as posted by jorisbleys, with a couple of exeptions:

                              1. The preloader is timeline based and the button that will launch the Flex 2 application is at the end of the timeline of the preloader. The addChild(container) does not load the Flex 2 app at this point.

                              2. the button at the end of the "preloader" is a MovieClip "button" (exported in first frame) called getstarted and has two frames, first frame is "get started", second frame will monitor download progress if Flex 2 application is not fully loaded, otherwise if it is fully loaded I would like it to start Flex app.

                              3. The caveat: I can get this to work by loading it into a "container" MovieClip, setting visibility to false, and other not so great coding technique; but... the main Flex app has custom cursor's and when it is loaded the custom cursor functions in the Flex app "takes over" the stage and the mouse disappears, although cursor events are still functioning with an invisible cursor. I assume this is because the visibility is false.... I hope this is detailed enough and thanks in advance for any help!

                              John

                              • 12. Re: stopping an external swf
                                xnomadx Level 1
                                Problem solved
                                • 13. Re: stopping an external swf
                                  kglad Adobe Community Professional & MVP
                                  why are you possibly adding container to the display list in showLoadResult and in showProgress and in gotoLoad?

                                  and when do you want to add container to the display list? when getstarted is released?
                                  • 14. Re: stopping an external swf
                                    xnomadx Level 1
                                    Thanks for the feedback. Hopefully this will address your questions, and hopefully the posted code looks a little better. And any feedback on this code is appreciated!

                                    There are three scenarios when users are viewing the "preloader".

                                    1. They can "skip intro", this is why I added the addChild(container) in the onShowProgress. Once "skip intro" is pressed, the "preloader" skips to end of "preloader" timeline to "getstarted" MovieClip(button). Once this is pressed, the "getstarted" MovieClip goes to frame 2 which displays the "loading" percentage if the "Flex2App" has not fully loaded. This allows for the user to view the download progress of the "Flex2App". The addChild(container) was removed from ShowLoadResult and just a Boolean value was recorded here to signify the "Flex2App" was fully loaded and ready to fire off.

                                    2. If the user watched the whole "preloader" and the "Flex2App" is not fully loaded, the showProgress will allow the user to click "getstarted" and go to frame 2 to view percentage progress, then "Flex2App" loads.

                                    3. User watches entire "preloader", before user come to end of timeline, "Flex2App" has fully loaded. User can then click "getstarted" and "Flex2App" loads.

                                    Couple of questions:
                                    Is this the correct use of <Stage.frameRate()>?
                                    Why do I have to create another loader on the "getstarted" button to work? I thought this was not necessary.


                                    • 15. Re: stopping an external swf
                                      kglad Adobe Community Professional & MVP
                                      1. no, that's not the correct use of frameRate. see below

                                      2. you can use the same loader and the same urlrequest in gotoLoad
                                      • 16. stopping an external swf
                                        xnomadx Level 1
                                        Thanks kglad.

                                        In the latest code I posted above, I just want to addChild(myLoader) without having to reload the "Flex2App", is this possible? Now it's starting the load again when it already is fully loaded. i.e. get rid of the

                                        myLoader.load(myRequest)

                                        or as in the code above

                                        loader.load(new URLRequest"Flex2App")?

                                        simlply putting addChild(myLoader) here is not working.....

                                        again, thank you for your help...!!

                                        edit: In the "getstarted" button code block.
                                        • 17. Re: stopping an external swf
                                          kglad Adobe Community Professional & MVP
                                          there's no need for that getstarted button and there's no need to restart loading of flex2app. you never use the close() method of your loader so it's continuing to load whether users bypass your intro or not.

                                          your showprogress function will still execute when you go to the end of the preloader timeline and it will still add flex2app to the display list when loading is complete.

                                          you can allow your user's to watch the intro or not watch it. and you can allow them to see the load progress of flex2app or not. but you do not appear to want to give them a choice about delaying its load and, in fact, your code does not delay its load under any circumstance handled by your posted code.
                                          • 18. Re: stopping an external swf
                                            xnomadx Level 1
                                            quote:

                                            Originally posted by: kglad
                                            why are you possibly adding container to the display list in showLoadResult and in showProgress and in gotoLoad?

                                            and when do you want to add container to the display list? when getstarted is released?


                                            Yes, when getstarted is released. I would like the user to hit getstarted and see the progress if the app is not fully loaded, then start the app, or, if the app is fully loaded to hit the same getstarted button and display the app.

                                            I don't think (how's that for noob) I want a delay in loading. Just trying to make the jump to as3.

                                            Thanks for all your help and input, it is greatly appreciated.

                                            The showProgress does not fire the app (when it is fully loaded) and hit the getstarted button....but I like your idea of not using it at all, I just can't wrap my brain around it.

                                            function gotoLoad(event:MouseEvent):void {
                                            getstarted.gotoAndStop(2);
                                            trace("pressed");
                                            event.updateAfterEvent();
                                            }

                                            • 19. Re: stopping an external swf
                                              kglad Adobe Community Professional & MVP
                                              here's a functioning preloader. start with this and then (slowly) add the additional code you need repeatedly checking for compile errors:

                                              • 20. Re: stopping an external swf
                                                xnomadx Level 1
                                                wow thanks for the quick reply. I will check this tomorrow. This will help a lot! This comes after days of searching on the web... Thanks.
                                                • 21. Re: stopping an external swf
                                                  kglad Adobe Community Professional & MVP
                                                  your welcome.