6 Replies Latest reply on Jul 30, 2010 10:02 AM by aditi_bk

    Moviecliploader onprogress not working

    aditi_bk Level 1

      Hello,

       

      I am using a moviecliploader to load landing.swf into a mcholder in parent.swf. Now even though the movie is loading fine, I am not able to display the loading percentage. The percentage always shows 100%. I am trying make a loader graphic run as per the percentage value, but since it is always at 100 the graphic does not work. I have tried testing it on the server as well, same thing, no loader graphic.

       

      Can anyone tell me why this is happening? Am I supposed to use a recurring function within the onloadProgress function???

       

      Any help will be greatly appreciated.

        • 1. Re: Moviecliploader onprogress not working
          Ned Murphy Adobe Community Professional & MVP

          Can you show/explain the code you are using?

          • 2. Re: Moviecliploader onprogress not working
            aditi_bk Level 1

            Hi Ned,

             

            The code is:

             

            var loader:MovieClipLoader = new MovieClipLoader();

            var ldrlistener = new Object();

            loader.addListener(ldrlistener);

            ldrlistener.onLoadStart = function(_mc:MovieClip) {
                trace("load started");
            };

            ldrlistener.onLoadProgress = function(_mc:MovieClip, loaded:Number, total:Number) {
                var prcnt:Number = Math.floor( ( loaded/total ) * 100 );

                if(prcnt==10)                    //diff labels within ldgraphic
                {
                    _root.ldgraphic.gotoAndPlay("ten");
                    trace("loading:10");
                }
                if(prcnt == 15) {_root.ldgraphic.gotoAndPlay("fifteen");
                                trace("loading:15");}
                if(prcnt == 20) {_root.ldgraphic.gotoAndPlay("twenty");
                                trace("loading:20");}
                if(prcnt == 25) {_root.ldgraphic.gotoAndPlay("twentyfive");
                                trace("loading:25");}
                if(prcnt == 30) {_root.ldgraphic.gotoAndPlay("thirty");
                                    trace("loading:30");}
                if(prcnt == 40) {_root.ldgraphic.gotoAndPlay("forty");
                                trace("loading:40");}
                if(prcnt == 50) {_root.ldgraphic.gotoAndPlay("fifty");
                                trace("loading:50");}
                if(prcnt == 55) {_root.ldgraphic.gotoAndPlay("fiftyfive");
                                trace("loading:55");}
                if(prcnt == 60) {_root.ldgraphic.gotoAndPlay("sixty");
                                trace("loading:60");}
                if(prcnt == 70) {_root.ldgraphic.gotoAndPlay("seventy");
                                trace("loading:70");}
                if(prcnt == 80) {_root.ldgraphic.gotoAndPlay("eighty");
                                trace("loading:80");}
                if(prcnt == 100) {_root.ldgraphic.gotoAndPlay("hundred");
                                trace("loading:100");}
            };

            ldrlistener.onLoadInit = function(_mc:MovieClip) {
                _root.ldgraphic._alpha = 0;              //the loader graphic become invisible after load
                trace("load completed");
            };

            loader.loadClip("home.swf",_root.mc_load);

             

            Now only "loading:100" is shown in the output and the loader graphic becomes invisible. home.swf starts playing. I know that the loader graphic is visible because when I removed the _alpha line I could see the graphic in its 100% state. Also, when I did a trace of prcnt values, it only shows 100. I checked this on the server as well, still the same thing happens.

            • 3. Re: Moviecliploader onprogress not working
              Ned Murphy Adobe Community Professional & MVP

              One thing you should do is be sure to clear your cache when testing this.  You should test it live on a server as well, or at least use the simulate download feature of the player if you have it.  The file being loaded might be too small or might be readily available in memory such that the loading doesn't get tested properly.

               

              Here's a couple things regarding the coding...

               

              While it depends on how large a file is being loaded, chances are you won't be hitting the exact prcnt values that your code tests for, so you will probably end up skipping frames and not seeing traces for all cases.  If you put a trace in the beginning of that function you will be able to see if the prcnt values are == to any of the tested values.

               

              I don't know what you have going on inside the ldgraphic movieclip, but using gotoAndPlay could be a problem if the file being loaded comes in slowly enough that you have repeats of values.  You may be better off using gotoAndStop if that movieclip stops in each frame you tell it to go to.

              • 4. Re: Moviecliploader onprogress not working
                aditi_bk Level 1

                Hi,

                 

                Thanks for the response. I tried making all the changes you mentioned, i.e. change gotoAndPlay to gotoAndStop and move the trace up. I also inserted this code into a relatively heavier file, but on doing that the movie has stopped loading. Also, in the same file, it is still only showing "loading:100" and no other values. I can't figure what could be causing this problem.

                 

                Please excuse my ignorance but how do you use the simulate download feature in Flash. I am using FLash CS4 and I cannot find that option under the Control button.

                 

                Thanks for all the help..:)

                • 5. Re: Moviecliploader onprogress not working
                  Ned Murphy Adobe Community Professional & MVP

                  When you test the file, in the player window select the View option and then select the Simulate Download option.  You can set the speed of the simulation as well.  I can't always get it to work, but it should.

                   

                  Just for the record.  I took your code and used it to load a 1.5 MB image file and get the following output with the trace added up front for prcnt.  You can see how it skips certain values....

                   

                  load started
                                      2
                                      5
                                      7
                                      10
                  loading:10
                                      13
                                      15
                  loading:15
                                      18
                                      20
                  loading:20
                                      23
                                      26
                                      28
                                      31
                                      33
                                      36
                                      39
                                      41
                                      44
                                      46
                                      49
                                      52
                                      54
                                      57
                                      59
                                      62
                                      65
                                      67
                                      70
                  loading:70
                                      72
                                      75
                                      78
                                      80
                  loading:80
                                      83
                                      86
                                      88
                                      91
                                      93
                                      96
                                      99
                                      100
                  loading:100
                  load completed

                  1 person found this helpful
                  • 6. Re: Moviecliploader onprogress not working
                    aditi_bk Level 1

                    Thanks Ned,

                     

                    Atleast I know the code works fine. I am now trying to get it to work with a bigger file, though something entirely different seems to have gone wrong ..This is my first time working with Flash, and am making a website, so still learning the ropes..its really great that pros like you take time out to help newbies like us...appreciate it..