4 Replies Latest reply on Jan 12, 2011 4:49 PM by Ned Murphy

    [HELP] External SWF with Movieclip Preloader included

    odhinn3

      Hi everybody,

      I've got a problem headaching me all afternoon long:

      Inside an SWF I want to load an external SWF inside an empty movieclip. On that frame I've got:


      emptymovieclip.loadMovie("external.swf");

       

       

      Inside the external SWF I've got a Preloader on the first frame consisting of a movieclip of 128frames. I'd like to appear from the first frame to the 128th related to loading percentage. When loaded it must go to fram 2 and this is the script on the movieclip:

       

      onClipEvent (load)
      {
         
      total = this.getBytesTotal();
      }
      onClipEvent (enterFrame)
      {
         
      loaded = this.getBytesLoaded();
         
      percent = int(loaded / total * 128);
         
      text = "Loaded " + percent + "%";
         
      gotoAndStop(percent);
          if (
      loaded == total)
          {
             
      this.gotoAndStop(2);
          }

      }

       

      Needless to say that it doesn't work and that's why I'm asking for your help.

      Everything is stopping at the first frame of the Preloader.

      I'm a bit noob for script-stuff as I'm not a programmer, sorry...

      HEEEEEELP!!

        • 1. Re: [HELP] External SWF with Movieclip Preloader included
          Ned Murphy Adobe Community Professional & MVP

          Your best friend in troubleshooting is the trace() function.  Place it as needed in your code to see what various values are at any point in time.  You are likely to find a particular value is not what you expect it to be.

           

          For example...

           

          onClipEvent (load)
          {
             
          total = this.getBytesTotal
          ();

               trace("total = "+total);
          }
          onClipEvent (enterFrame
          )
          {
             
          loaded = this.getBytesLoaded
          ();
             
          percent = int(loaded / total * 128
          );

              trace("percent = "+loaded+" / "+total+" = "+percent);
             
          text = "Loaded " + percent + "%"
          ;
             
          gotoAndStop(percent
          );
              if (
          loaded == total
          )
              {
                 
          this.gotoAndStop(2
          );
              }

          }

          • 2. Re: [HELP] External SWF with Movieclip Preloader included
            landar

            You might take a close look at your variable definitions. Perhaps they are not being interpreted correctly. For instance, normally I would expect to see "var" in front of total but maybe you are not including all of the code. I would further type the variable total like so:

            var total:Number = this.getBytesTotal();

             

            This leaves no misunderstanding as to what you are comparing.Scope of variables and definition are extremely important and sometimes overlooked.

            • 3. Re: [HELP] External SWF with Movieclip Preloader included
              odhinn3 Level 1

              Thanks for the replies.

              I tried to follow both of your hints but barely understanding the method and the explanation probably related to my low experience.

              I've found out that the problem seems solved if I write _root instead of this... but just in the external SWF preview. When it's loaded inside the main one... no way. I fell like being very close to the solution but dunno how... any of you, pretty please? :-)

               

              Now the full script is:

               

              onClipEvent (load)
              {
              var total:Number = _root.getBytesTotal();
                   trace("total = "+total);
              }
              onClipEvent (enterFrame)
              {
                  loaded = _root.getBytesLoaded();
                  percent = int(loaded / total * 128);
                       trace("percent = "+loaded+" / "+total+" = "+percent);
                  text = "Loaded " + percent + "%";
                  gotoAndStop(percent);
                  if (loaded == total)
                  {
                      _root.gotoAndStop("end");
                  }
              }
              
              

               

               

              Anyway, I'd like to share with you the files, just in case they could help to solve the "stupid" problem.

              http://www.designsociety.it/testfiles.rar

              Thanks!

              • 4. Re: [HELP] External SWF with Movieclip Preloader included
                Ned Murphy Adobe Community Professional & MVP

                If you put

                 

                _lockroot = true;

                 

                in the main timeline of the external swf, it will refer to it's own _root anytime you use a _root reference in its code.  Otherwise, it refers to the _root of the main file that loaded the swf.  So if it works using _root when you run the external file separately, then it should wotk if you add that line.