24 Replies Latest reply on Aug 4, 2009 3:25 AM by fenosc

    Extremely simple preloader problem.

    fenosc Level 1

      Hi there,

       

      I have a really simple preloader and it doesn`t seem to work. My flash stays white until loaded, and then it simply shows the 100% message.

      I never made one, so I may be doing something basic wrong.

       

      Ill post the small sequence of code that is used for this:

       

      customLoader = new customLoader(this);
      customLoader .addEventListener(Event.COMPLETE, onLoadComplete, false, 0, true);
      customLoader .Load();

       

      inside custom load class

       

      _main = Amain; // Amains is the parameter that was send to this clas (the "this" mentioned before)

      loaderImage = new loader_mc() //just a movieclip with a little drawing

       

      //sequence of code that makes my preloader animation

      //here I just addChild with a symbol e make a tweening of it using TweenLite

      main.loaderInfo.addEventListener (ProgressEvent.PROGRESS, loading);

      main.addChild(loaderImage);

       

      private function carregando(evt:ProgressEvent):void {
          var pcent:Number = evt.bytesLoaded/evt.bytesTotal*100;
           trace(pcent);
           if (pcent == 100) {
               onComplete();
           }           
      }

       

      the oncOmplete function runs fine (it`s when the loaderImage shows on screen...)

      But the loaderImage was supposed to show earlier... i really don`t get it.

       

      One thing I should mention, everything in my project was exported to action script with the Export to frame 1 UNCHECKED.

      Behalf the loading stuff. Every image from loading that I use was exported to frame 1. (checked)

      I thought this was a good practice but I don`t really know. I read somewhere that things exported to frame 1 are loaded before everything.

       

      Any help is apreciated, thanks!

        • 1. Re: Extremely simple preloader problem.
          kglad Adobe Community Professional & MVP

          what's main?

           

          what's Load()?

           

          onComplete() may be called before loading is complete.  use a COMPLETE event in your class to call onComplete().

           

          is onLoadComplete() ever called?

          • 2. Re: Extremely simple preloader problem.
            fenosc Level 1

            I`m sorry, I did a little mistake over there

             

            This function is the Load() function I wrote:

            private function Load(evt:ProgressEvent):void {  // I copied from my code up there and forgot to change the name,
                var pcent:Number = evt.bytesLoaded/evt.bytesTotal*100;
                 trace(pcent);
                 if (pcent == 100) {
                     onComplete();
                 }           
            }

             

             

            The onComplete function is called, the problem is that the preloader animation doesn`t play. The screen stays white and the suddenlty my page begins (that is the onComplete function).

             

            Main is the document class, since my loader is a class and I needed the main stuff there I passed it as a parameter.

            The oncomplete is being called when everything is loaded, is there something wrong here that I`m missing? Do I really need to use the COMPLETE event to call it ? Since it will be called only when the pcent is 100%, I didn`t thought about a problem there.

            The problem is just the animation not being played.

             

            Thanks again!

             

            ps. the trace doesn`t work either. It appears only when it is 100%

            • 3. Re: Extremely simple preloader problem.
              kglad Adobe Community Professional & MVP

              what's main?

               

              onComplete() may be called before loading is complete.  use a COMPLETE event in your class to call onComplete().

               

              is onLoadComplete() ever called?

              • 4. Re: Extremely simple preloader problem.
                fenosc Level 1

                Hi there,

                I wrote on the above post that the Main is my document class.

                The onComplete function is not being called before the complete. I added trace commands to it and to the Load function and it shows that it only enters onComplete after the load.

                 

                Anyway I changed it

                //I dont really know where to put the loaderInfo, so I just putted in the main class(document class). This main variable represent the document class in

                //the customLoader class.

                main.loaderInfo.addEventListener (ProgressEvent.PROGRESS, Load);
                main.loaderInfo.addEventListener(Event.COMPLETE, onComplete);

                private function Load(evt:ProgressEvent):void{
                    var pcent:Number = evt.bytesLoaded/evt.bytesTotal*100;
                    trace(pcent); //just shows the 100%, never something lower

                }

                 

                private function onComplete(evt:Event):void {

                   //playsite, the trace here shows after the 100% from the load function

                }

                 

                Also, I don`t have onLoadComplete function. If by that you mean my onComplete function, yes it does. My site plays normaly.. the only problem is that the loading animation is not playing. It is jumping from a white screen right to the first animation.

                 

                Thanks again

                • 5. Re: Extremely simple preloader problem.
                  kglad Adobe Community Professional & MVP

                  Main is likely your document class.  even though you think main and Main are similar and somehow related it's not clear to anyone the reads your messages what main is.

                   

                  are you passing a reference to you main timeline in Main's constructor and that's what main is?

                  • 6. Re: Extremely simple preloader problem.
                    fenosc Level 1

                    Hi kglad,

                    Yes, Main is my document class.

                    When i call the customLoader constructor I do it like this in my Main class (document class)

                     

                    class Main

                     

                    var customLoader = new CustomLoader(this);
                    customLoader .addEventListener(Event.COMPLETE, onLoadComplete, false, 0, true);
                    customLoader .Load();

                     

                    private function onLoadComplete(evt:Event):void {

                       //play site

                    }

                     

                    and that triggers the constructor, which receives the instance of the document class.

                     

                    I just don`t get it why my loader movieclip doesn`t show on stage right when the swf starts since it is exported to frame 1 and I have the addChild right in constructor.

                     

                    This is part of my CustomLoader class

                            private var main:MovieClip

                            private var mcLoading:loader_mc; //this is the loading animation image

                     

                    public function Carregador(Amain:MovieClip): void {
                          //Inicializations.
                          main = Amain;
                           mcLoading = new loader_mc();
                          mcLoading.x = main.stage.stageWidth/ 2;
                          mcLoading.y = (main.stage.stageHeight -70)/2;

                          TweenMax.to(mcLoading.mcBorder, 0, {dropShadowFilter: { color:0x000000, alpha:.5, blurX:12, blurY:12, distance:8 } } );

                     

                          this.addEventListener("onFinishedAnimation", onFinishedAnimation, false, 0, true);

                          main.addChild(mcLoading);

                    };

                     

                    //This function is called to load. What it does is just instancing a mask and adding to my mcLoading movieclip. Then animate it.

                    private function Load():void {

                         //After making the mask animating and adding to the mcLoading movieclip

                         main.loaderInfo.addEventListener (ProgressEvent.PROGRESS, loading);

                         main.loaderInfo.addEventListener(Event.COMPLETE, onComplete);    

                    }

                     

                    private function loading(evt:Event):void {

                           var pcent:Number = evt.bytesLoaded/evt.bytesTotal*100;
                           trace(pcent); //I just wanted to be shown in the output for now... when it works I`ll add it to my text in the movieclip.

                    }

                     

                    private function onComplete(evt:Event):void {

                         //Here I just make sure that the loading animation is finished before calling the site animation

                        dispatchEvent("onFinishedAnimation");

                    }

                     

                    private function onFinishedAnimation(evt:Event):void {

                       //Standby state until the use clicks the button and the site is played in the Main class.

                      //This function is the part that is shown....

                      //Everything since the pcent = 100% happends normally. The problem is that it doesnt show the loading for 1 to 99%.

                    }

                     

                    I hope this can explain better my situation.

                    Oscar

                    • 7. Re: Extremely simple preloader problem.
                      kglad Adobe Community Professional & MVP

                      what's calling Carregador() and what movieclip is being passed?

                       

                      actually, why is this so messy?  are you doing anything other than creating an instance of your preloader to display the load progress of the main swf?

                      • 8. Re: Extremely simple preloader problem.
                        fenosc Level 1

                        God, I did it again.

                        I`m translating my code when I put it here so it can be easier for you to understand. But when i`m reading the code to check if I let something in portuguese sometimes it passes by me.

                         

                        Carregador() is the constructor of the CustomLoader class and the THIS is the Main (documentclass) that is being passed to it,

                         

                        Well, what I`m doing is loading a movieclip from my library into my CustomLoader class. I make an animation and apply to the movieclip. When it finished I need to make sure that the preloader finishes its animation (just to don`t have any glitches). Then I make another animation that just waits for the user to click on it. Then the Main class will play the site animation.

                         

                        I`m attaching a file with the actionscript entirely translated with the important parts only.

                        (The ones I showed here and some more, including animation code)

                         

                        It is not much. But I may be doing something basic wrong.

                        I think it is easier than just adding codes here when its hard to read it.

                        Thanks again for your time and patience Kglad.

                         

                        ps. code here also: http://www.comp.ufscar.br/~ellmann/odr/textos/formacao/laoderClass.txt

                        • 9. Re: Extremely simple preloader problem.
                          kglad Adobe Community Professional & MVP

                          it doesn't make any sense to use a preloader for movieclips that are added from the library.  they're added instantly.

                          • 10. Re: Extremely simple preloader problem.
                            fenosc Level 1

                            Err.. I don`t know what you mean by that.

                             

                            My file has 400kb. And to load it the screen stays white the whole time until it is loaded and the video is played.

                             

                            I want there to be a little loader while the file is loaded to then play the file.

                            That is why a preload is done right ?

                             

                            The things that are in my library and exported to swf are just graphic stuff that I need to position and then use code to make them work...

                            • 11. Re: Extremely simple preloader problem.
                              debb4jc

                              please remove my nam from all flasher list thanks Debbie Gragg thanks

                              • 12. Re: Extremely simple preloader problem.
                                fenosc Level 1

                                Hi there,

                                 

                                Well, I was looking over the internet and it seems that my question is not as dumb as I thought.

                                My flash file is empty, it has just items in its library that are exported to action script and then there I make all the magic.

                                 

                                What I mean is: My FLA file has just a blank keyframe... nothing there.

                                 

                                It seems that flash loads everything exported to actionscript before the first frame is shown. Even though I have unchecked the export to frame 1 option of everything, behalf from the loader stuff.

                                 

                                Is it a little better explained?

                                oscar

                                • 13. Re: Extremely simple preloader problem.
                                  kglad Adobe Community Professional & MVP

                                  you can use a preloader for you main swf but you'll need to place the preloader before your library items are loaded.

                                   

                                  you can load your library items by unchecking that box that says to export in frame 1 AND changing the frame which flash uses to load classes (file/publish settings/flash/settings and change the frame number).

                                  • 14. Re: Extremely simple preloader problem.
                                    fenosc Level 1

                                    Hey kglad, that`s new for me! Now I we are getting somewhere. I think.

                                     

                                    I did understand how to change the frame to load the stuff, but not exacly how to do use it and make it work.

                                    I changed my flash file to export everything on frame 2 and added a stop() to frame 1 (even though there is no animation nor objects i the timeline). But then, when I see the properties of my loading objects in the library, they are all being exported to frame 2. This is causing problems because when I try to access the instances of my loading object, they don`t exist. They will exist only on frame 2.


                                    Well, they (loading stuff) should be exported to frame 1, while all the other classes from my site should be exported to frame 2. Any idea on how do I do that?

                                     

                                     

                                    For the time being I`ve solved my problem making a SWF load my site. Then I have the preloader in 1 swf and my site in other.

                                    But I really dislike this solution. I reall want to learn how to make it in one file.

                                     

                                    Is there a way to export specific object from my library to frame 1, before everything else ? (actually, I thought I was doing this when I unchecked the "export to frame 1" option... but seems like I was wrong... when I uncheck that box, where are my stuff exported?)

                                     

                                    Oscar

                                    • 15. Re: Extremely simple preloader problem.
                                      kglad Adobe Community Professional & MVP

                                      all classes must have the same export frame so you'll need to separate your preloader from any class files.

                                      • 16. Re: Extremely simple preloader problem.
                                        fenosc Level 1

                                        Yes indeed,

                                        That I`m aware of, but how do I accomplish that?

                                        I tried in two ways that I could think of:

                                         

                                        When I had the exmport all classes to frame 1 in the publish settings: only the loader was exported in frame 1 (I thought this way that the other wouldnt)

                                        When I had the exmport all classes to frame 2 in the publish settings: only the loader was NOT exported in frame 2 ( I thought that it would be exported maybe on frame 1). Everything else was exported to frame 2.

                                         

                                        But neither worked.

                                        How do I acchieve that?

                                        Oscar

                                        • 17. Re: Extremely simple preloader problem.
                                          kglad Adobe Community Professional & MVP

                                          the loader shouldn't be exported, at all, because you want it to appear before exported classes are loaded.

                                          • 18. Re: Extremely simple preloader problem.
                                            fenosc Level 1

                                            Hi Kglad

                                             

                                            Ok, so the loader shouldnt be exported, it should be in the first frame of my flash IDE, with a instance name and then I should play with it in my document class, correct? Also, all the other stuff is exported to frame 2.

                                             

                                            Well, I putted my loading_mc in the flash ide, added a instance name and then runned the movie, but the I get an error.

                                             

                                            ReferenceError: Error #1056: Cannot create property mcLoading on Main.
                                                at flash.display::Sprite/constructChildren()
                                                at flash.display::Sprite()
                                                at flash.display::MovieClip()
                                                at Main()

                                             

                                            Main is my Document Class and mcLoading is the instance name of my loading_mc.

                                             

                                            I putted some trace to find where it is happening and I figured that not even a trace as the first command in my document class shows up in my output pannel.

                                            Any ideas why this happend?

                                             

                                            By the message in the error I would assume that my loading_mc wouldn`t show on screen... but weirdly enought it does... but my document class isnt executed.

                                            • 19. Re: Extremely simple preloader problem.
                                              kglad Adobe Community Professional & MVP

                                              the problem's in Main.  i can't tell what you're doing that's causing the problem.

                                              • 20. Re: Extremely simple preloader problem.
                                                fenosc Level 1

                                                Hm... I can`t understand this at all...

                                                 

                                                I comented my whole Main class, everything, with the exception of the constructor declaration (empty by the way)

                                                 

                                                And it still gives me the same error.

                                                I think it is not related to it... I`m really getting tired of flash

                                                • 21. Re: Extremely simple preloader problem.
                                                  kglad Adobe Community Professional & MVP

                                                  does Main extend the movieclip class?  if it extends the sprite class and you have any code on a timeline, you'll have problems.

                                                  • 22. Re: Extremely simple preloader problem.
                                                    dalcde Level 1

                                                    Actually it will always start from 100% if you are publishing directly from Flash. Try put it into an HTML.

                                                    I don't see why an extremely simple problem takes 21 posts but still isn't solved?

                                                    • 23. Re: Extremely simple preloader problem.
                                                      fenosc Level 1

                                                      Hey kglad,

                                                       

                                                      It is extending the movieclip class.

                                                       

                                                      Thanks for your patience during this problem but I already gave up.

                                                      I made my movie load through another swf and now it works. Unfortunaltly I didn`t start correctly my site and changing would be too much trouble.

                                                       

                                                      Next time I`ll make the preloader on Flash stage and not by code and then add it to the stage via addChild command.

                                                       

                                                      I`m really gratefull for your help

                                                      Just in case you were curious, this is the site I was busy with

                                                      www.comp.ufscar.br/~ellmann/odr

                                                       

                                                      It`s my first attempt with actionscript and I learned alot with it... scrollbars, mousewheel, loader, links, reading txt files, dynamic windows and others.

                                                       

                                                      Thanks again

                                                      Oscar

                                                      • 24. Re: Extremely simple preloader problem.
                                                        fenosc Level 1

                                                        Seems like it wasnt quite simples as I thought right ? =\