14 Replies Latest reply on Sep 17, 2007 8:50 AM by SymTsb

    Preloading in the swf itself AS3

    Flamebg Level 1
      Hello guys ;]

      I need some help in AS3.

      My problem is that I can't preload the content in the swf movie itself.. I mean movie clips and images that are inside the swf not external and so on.

      In AS2 All I needed to do is this :

      this.onEnterFrame = function() {
      loadingAmount = this.getBytesLoaded()/this.getBytesTotal()*60;
      if (loadingAmount == 60 and sVars.loaded == true and this.bigPicWidthsScript_mc.wVars.loaded == true) {
      this.gotoAndStop(3);
      delete this.onEnterFrame;
      }
      };

      This is juat an example what used to work.. I copied this part from a code I wrote time ago in AS2.
      So all u had to do is put this code on frame 1 along with some preloading graphics (small size), move all your movie clips u want loaded before they actually show up and start your animation to frame 2 as keyframe, and Put the ones who show up at the start in your movie at frame 3 where you actually go when preloading is finished.

      So I want to do the same thing in AS3.. I've found tutorials about preloading swfs images and so on but I don't need that.. I need this one here.. so does anyone have any idea how to do that ?

      I will be very grateful !

      Waiting for replies,
      Filip Nedyalkov
      Also u had to set Export frame for classes = 2 (in the publish settings),
        • 1. Re: Preloading in the swf itself AS3
          kglad Adobe Community Professional & MVP
          use your loader's loaderInfo property's bytesLoaded and bytesTotal properties in an as3 loop (ENTER_FRAME or timer). there may be problems with setInterval() in as3.
          • 2. Re: Preloading in the swf itself AS3
            Flamebg Level 1
            thanks kglad,
            but can you be more specific please..

            I am not using any loader because I don't want to load the same swf in itself..
            I just didn't understand what you tried to explain to me, maybe you can write me an example just like I did on AS2 please ?
            In Flash Help I couldn't find anything about bytesLoaded and so on.. in the examples there they show how they create loader and load the swf in it.. but I don't want to make separate flash with just one loader in it so I can load my actual swf with preloader..
            I don't know if you understand what I am trying to say but I hope u do..

            Waiting for more detailed reply,
            Filip Nedyalkov
            • 3. Re: Preloading in the swf itself AS3
              SymTsb Level 2
              Are you talking about simply preloading your base swf file?

              Are you testing in IE? - Known problems with this in IE if your answer to my first question is indeed a yes.
              • 4. Re: Preloading in the swf itself AS3
                Flamebg Level 1
                Yes, I want to preload my base swf file, but I don't know how to write the code with AS3 and I don't seem to find simmilar coding to the one at AS2 (as I posted). So I think I am far away from common problems with IE just yet ;]
                • 6. Re: Preloading in the swf itself AS3
                  C-Rock Level 2
                  I made a document class called "Preloader" and used the code below, it seems to work fine.

                  • 7. Re: Preloading in the swf itself AS3
                    C-Rock Level 2
                    you don't really need the transition imports, i was using them in other as files and just loading them here...
                    • 8. Re: Preloading in the swf itself AS3
                      Flamebg Level 1
                      thanks a lot guy for the help ;] I am very very very grateful ;D
                      • 9. Preloading in the swf itself AS3
                        Flamebg Level 1
                        hei guys, sorry to bring back this topic but I have a little problem with the tutorial SymTsb gave above.

                        I rewrote a bit the code from there so now I have this one : attached at bottom!

                        The problem is that it doesn't work correctly.

                        The file is Root.as and I've set name of the Document class to "Root" and it works but finds 2 mistakes. I will post them for you.. I hope you know what's wrong because I didn't change this part of the code and it turns out wrong for me .. and I don't know why.. so there you go:

                        1046: Type was not found or was not a compile-time constant: SimpleButton. | import flash.events.*;

                        1046: Type was not found or was not a compile-time constant: TextField. | public static var _root:MovieClip;

                        In my fla file I have stop(); at my first frame and I also have a dynamic text field instance called prcLoaded on the stage.

                        So what is wrong ? :-/

                        Regards,
                        Filip Nedyalkov
                        • 10. Re: Preloading in the swf itself AS3
                          SymTsb Level 2
                          Change your import flash.display.MovieClip; to import flash.display.*; Let me know what impact that has on the SimpleButton issue.

                          The other error is a reference to this. change _root = this to...

                          _root = MovieClip(this);
                          all remaining reference to this for the listeners can be changed to _root after that.

                          Words of wisdom. Do not use Root as the main class name. Change it to something like Preloader which is exactly what this file does and avoid the use or AS2 reserved words in your AS3 scripts. I see this constantly, and the truth is you can achieve the exact same thing by adding a timeline target to your classes constructor and sending it to the class. Then you can just reference the target variable and avoid the problems that will occur because of using invalid markup or names.
                          • 11. Preloading in the swf itself AS3
                            Flamebg Level 1
                            ok I did what you said, I will attach the current code below, the simpleButton issue is now gone but the other one remains:

                            1046: Type was not found or was not a compile-time constant: TextField. | public static var _root:MovieClip;

                            I did changed the name of the file and the class name as you adviced :)
                            So what is this error now about ?
                            And maybe you can explain to me what was that with flash.display.MovieClip; thing.. * is for import all classes as far as I know, so if it is not the movie clip class that it is used it must be some other and you are not sure which so we import all ?
                            I really hope you can solve the last problem too :) I could use this code to preload all of my next flashes I make ;]
                            Besides that if you know some other way I can adress the main timeline in the flash file itself will be good to know too or maybe this one works either ways ? But first we got to make it work :D

                            Ok I will be happy to hear from you soon, you are really helpful ;] thanks a lot
                            • 12. Re: Preloading in the swf itself AS3
                              Flamebg Level 1
                              Still waiting for reply ;]
                              • 13. Preloading in the swf itself AS3
                                Flamebg Level 1
                                ok.. thanks to my own help I fixed this problem by adding:
                                import flash.text.TextField;

                                I've read the help about this package and I just don't get it.. how this import can fix a problem with declining a variable.. when it's supposed to be about creating textFields.. If anyone could at least clear this thing out for me that would be good ;]

                                And btw the most stupid thing of all is that when I finally got it working.. I find out that it works in Firefox and still have the same problem as AS2... not working in IE.. hits 100% and that's it.. doesn't recognise complete event.. so basicly these progress following events are kinda useless..

                                So I had to make a workaround with enter frame which works both browsers...
                                All this kinda sux...

                                Regards,
                                Filip Nedyalkov
                                • 14. Re: Preloading in the swf itself AS3
                                  SymTsb Level 2
                                  The reason you need it is because you are using the .text property on a member of the _root object. (I'm guessing but it wouldn't surprise me).

                                  About the import statement
                                  This is a personal philosophy and I'm open to valid suggestion here but the Flash Player looks at your code and builds a list of all the different classes that will be required at run-time and need to included in the compressed swf. If you an import like this....

                                  import flash.display.*;

                                  you are in theory including all of the classes inside of the flash display package. This is not actually the case. Even if you include the entire package in your code, all you are actually doing is telling Flash that this path/package is available for searching for the classes you are using in your document. Flash is only going to include a list of "necessary" classes when it runs its compile for your swf so keep that it mind. It is actually better to include the entire package set in my opinion thus playing it safe.

                                  It is a known bug and issue with preloading code inside IE6(7?) that prevents any kind of update being pulled from the browser concerning a files download. I've only had this issue in IE7 myself but this doesn't affect me or work since I typically only use the top level of a swf as a container for individual swfs which I load in using the Loader class. You can read more about the problem here (leads off to Actionscript.org forums with related post on topic)...

                                  http://pixelfumes.blogspot.com/2007/07/ie6-as3-preloader-events-failing.html