12 Replies Latest reply on Jun 5, 2011 11:43 AM by kglad

    Preloader for loadMovie in AS2?

    rowancavanagh

      First things first, please don't recommend I change to AS3 for this. It's far too late for that and not my project to be dictating.

       

      So I'm loading some external swfs in with the loadMovie command, in the normal manner with a button:

      on (release) {
          loadMovie("swfs/example-1.swf", _root.container);
      }

       

      But what I need, is to wedge a preloader in there somehow. As the swfs are around 1mb each.

       

      I'm already using the following as a preloader for the main file, so an adaptation of it would be very welcome so I can co-ordinate the graphics:

      var amountLoaded:Number = _root.getBytesLoaded() / _root.getBytesTotal();
      preloaderText.text = Math.round(amountLoaded * 100) + "%";

       

      ---

      if (_root.getBytesLoaded() == _root.getBytesTotal())
      { gotoAndPlay(3); }
      else
      { gotoAndPlay(1); }

       

      So would there be a way to wedge my preloader into that first lot of code?

        • 1. Re: Preloader for loadMovie in AS2?
          kglad Adobe Community Professional & MVP

          is that a true button or a movieclip button?  (and, you really shouldn't attach code to objects).

          • 2. Re: Preloader for loadMovie in AS2?
            rowancavanagh Level 1

            Yep, it's a true button

            • 3. Re: Preloader for loadMovie in AS2?
              kglad Adobe Community Professional & MVP

              on (release) {
              preloadI=setInterval(preloadF,100,_root.container)     loadMovie("swfs/example-1.swf", _root.container);
              }

               

              // attached to the frame that contains your button

              funtion preloadF(mc:MovieClip){
              var amountLoaded:Number = mc.getBytesLoaded() / mc.getBytesTotal();
              preloaderText.text = Math.round(amountLoaded * 100) + "%";

               

              if (mc.getBytesLoaded() == mc.getBytesTotal() & mc.getBytesTotal()>0){
              clearInterval(preloadI);
              // do whatever
              }
              }
              1 person found this helpful
              • 4. Re: Preloader for loadMovie in AS2?
                Rothrock Level 5

                Unless you are publishing to a very low target player, you might want to look at using the MovieClipLoader class instead of loadMovie and an old-school preloader.

                 

                The MCL class gives you some nice events such as onLoadError that you won't get with the hand-made approach.

                • 5. Re: Preloader for loadMovie in AS2?
                  rowancavanagh Level 1

                  I realise this will be terrible feedback, but it didn't work

                   

                  Here's what I put in the button:

                  on (release) {
                      preloadI=setInterval(preloadF,100,_root.container)
                      loadMovie("swfs/example-1.swf", _root.container);
                  }

                   

                  And here's what I put in the containing frame:

                  function preloadF(container:MovieClip)
                  {
                      var amountLoaded:Number = container.getBytesLoaded() / container.getBytesTotal();
                      preloaderText.text = Math.round(amountLoaded * 100) + "%";
                      if (container.getBytesLoaded() == container.getBytesTotal() & container.getBytesTotal() > 0)
                      {
                          clearInterval(preloadI);
                      }
                  }

                   

                   

                  So I have no idea what went wrong really.

                  • 6. Re: Preloader for loadMovie in AS2?
                    kglad Adobe Community Professional & MVP

                    copy and paste the output panel result:

                     


                    on (release) {

                    trace("btn "+this);
                        preloadI=setInterval(preloadF,100,_root.container)
                        loadMovie("swfs/example-1.swf", _root.container);
                    }

                     

                     

                    trace("preloadF "+this);

                    function preloadF(container:MovieClip)
                    {
                        var amountLoaded:Number = container.getBytesLoaded() / container.getBytesTotal();
                        preloaderText.text = Math.round(amountLoaded * 100) + "%";

                    trace(preloaderText+" "+amountLoaded);
                        if (container.getBytesLoaded() == container.getBytesTotal() & container.getBytesTotal() > 0)
                        {
                            clearInterval(preloadI);
                        }
                    }

                     

                     

                    So I have no idea what went wrong really.

                    1 person found this helpful
                    • 7. Re: Preloader for loadMovie in AS2?
                      rowancavanagh Level 1

                      Output from that:

                       

                      preloadF _level0
                      btn _level0.instance3

                      • 8. Re: Preloader for loadMovie in AS2?
                        kglad Adobe Community Professional & MVP

                        you're using a movieclip button, not a true button.  use:

                         


                         


                        on (release) {


                            _parent.preloadI=setInterval(_parent.preloadF,100,_root.container)
                            loadMovie("swfs/example-1.swf", _root.container);
                        }

                         


                        function preloadF(container:MovieClip)
                        {
                            var amountLoaded:Number = container.getBytesLoaded() / container.getBytesTotal();
                            preloaderText.text = Math.round(amountL*100)+"%";
                            if (container.getBytesLoaded() == container.getBytesTotal() & container.getBytesTotal() > 0)
                            {
                                clearInterval(preloadI);
                            }
                        }

                         

                         

                         

                        • 9. Re: Preloader for loadMovie in AS2?
                          rowancavanagh Level 1

                          ah, thankyou. That seems to work just fine

                           

                          I assumed because even though my button is inside a movie clip, as it is button, it was still considered a true button.

                           

                          Now there is another problem, I know its not part of the preloader business, but its still relevant:

                          The swf I load in with loadMovie appears before it's completely loaded. How do i stop this?

                          • 10. Re: Preloader for loadMovie in AS2?
                            kglad Adobe Community Professional & MVP

                            assign the _alpha of your target movieclip to 0 until loading is complete.  then direct its timeline to frame 1 and assign its _alpha to 100.

                            • 11. Re: Preloader for loadMovie in AS2?
                              rowancavanagh Level 1

                              ah thanks. I was trying _visible and it wouldn't quite work for me.

                               

                              Anyway. All done.

                               

                              cheers

                              • 12. Re: Preloader for loadMovie in AS2?
                                kglad Adobe Community Professional & MVP

                                you're welcome.