1
votes

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

1
Take a look at my answer to a similar question: stackoverflow.com/questions/8410774/… - package

1 Answers

2
votes

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.
        //
        //
    }

}