1

I've googled a lot and couldn't find anything except timeline based pre loaders or external pre loaders (loading external swfs).

I'm looking for Document class preloaded that has even library symbols exported for the first frame.

Please advise.

I also have private variables inside document class referring to those exported clips.

public var menu:Menu;
public var brand:MovieClip;
public var container:MovieClip;
public var background:Background;
public var intro:Intro;
public var language:Language;

plus lots of clips exported by flash itself on the frame 1, for instance Combobox, (screenshot below)

enter image description here

  • Take a look at my answer to a similar question: http://stackoverflow.com/questions/8410774/how-to-create-preloader-in-as3/8411615#8411615 – package Jun 05 '12 at 08:30

1 Answers1

2

You just need to use root.loaderInfo's bytesTotal and bytesLoaded properties.

When they are equal to eachother, you've loaded 100% of the SWF and you can manage what should happen next accordingly.

Sample:

package
{

    import flash.display.Sprite;
    import flash.events.Event;


    /**
     * Document class.
     */
    public class Document extends Sprite
    {

        // Constructor.
        public function Document()
        {
            addEventListener(Event.ENTER_FRAME, _loadStatus);
        }


        // Manage the current status of the preloader.
        private function _loadStatus(e:Event):void
        {
            if(loadPercent >= 1)
            {
                removeEventListener(Event.ENTER_FRAME, _loadStatus);

                beginApplication();
            }
        }


        // Load complete, being the application here.
        protected function beginApplication():void
        {
            trace("Loaded.");
        }


        // Returns a number representing current application load percentage.
        protected function get loadPercent():Number
        {
            return root.loaderInfo.bytesLoaded / root.loaderInfo.bytesTotal;
        }

    }

}

I must also note that exporting all your library symbols on the first frame is a bad idea - you need to make sure they aren't exported on the first frame.

Bonus: Having the above class as the base class of your actual document class makes for a really tidy application entry point (where you begin coding your application):

public class MyDocument extends Document
{

    override protected function beginApplication():void
    {
        // Application has loaded.
        // Your initialize code here.
        //
        //
    }

}
Marty
  • 39,033
  • 19
  • 93
  • 162
  • Thanks for the answer, but the problem is that If I set the clips to export to frame 2, I'm getting all sorts of errors, for instance I've private variables inside Document class referring to those clips, edited my question to include them. –  Jun 05 '12 at 08:43
  • @iPhoneDeveloper Yep, so to get around that you have to initialize a class containing those references AFTER the document has loaded, which will get around those errors. What will happen with everything exported on the first frame is that the preloader (if you have one) might not even show up until the document is 90% loaded because everything else is clogging up the load. You may as well not have a preloader if everything is exported in the first frame. – Marty Jun 05 '12 at 08:52
  • agree but then I've to change each clip, no problem if i've like one or two but I noticed so many components from flash itself exporting itself to frame 1 and even moving them to frame 2 will introduce more errors, attached screenshot to the question –  Jun 05 '12 at 09:01
  • @iPhoneDeveloper You can shift-select your symbols and then right click->properties to modify multiple at once. Alternatively you can go File->ActionScript settings and then change the value of the field marked 'Export classes in frame [1]'. – Marty Jun 05 '12 at 09:10