swftools-common
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Swftools-common] Preloading Images.


From: Richard Anderson
Subject: [Swftools-common] Preloading Images.
Date: Thu, 12 Feb 2009 16:33:10 -0600
User-agent: Thunderbird 2.0.0.19 (X11/20090102)

Greetings, all.

I'm writing what is essentially a fancy slide show using SWFC.  On load,
the slideshow requests a list of images using loadVariables.  The
response to this request ends with "eof=true" so I can tell when it's
done loading.I've got a preload screen which waits for this request to
finish and then replaces its own onEnterFrame with a function that
*should* be waiting for all of the images to preload.  Unfortunately,
I've had no luck with getBytesLoaded() and getBytesTotal().

I don't need a progress bar, and if there's a better way to go about
this, I'm open to it.

Here's a code snippet:
    .sprite loader
        .frame 1
            .put loading_animation pin=center x=360 y=203
        .frame 13
            .change loading_animation rotate=330

        .action:
            this.onEnterFrame=function()
            {
                if (_root.eof == "true" && this.ranonce==undefined)
                {
                    // To make sure this doesn't get run twice if it
takes longer than one frame to finish everything.
                    this.ranonce=true;

                    // Some housekeeping stuff here.

                    _root.createEmptyMovieClip("holder", 2);
                    _root.holder._visible = false;

                   // Sets this.toload to an array of the following form:
                   // ["/path/to/image.jpg","/path/to/image.jpg",...]
                   this.toload = _root.getImagesToLoad();

                    this.onEnterFrame=function()
                    {
                        next = false;

                        if (this.loadindex == undefined)
                        {
                            this.loadindex = 0;
                            next = true;
                        }
                        else
                        {
                            loaded = _root.holder.getBytesLoaded();
                            total = _root.holder.getBytesTotal();
                            if (total > 0 && loaded == total && loaded
!= undefined && total != undefined)
                            {
                                this.loadindex++;
                                next = true;
                            };
                        };

                        if (next)
                        {
                            if (this.loadindex > this.toload.length-1)
                            {
                                // Add controls, the slide movie clip,
start the slideshow playing, etc...
                                this.stop();
                                this._visible = false;
                                delete this.onEnterFrame;
                                return;
                            };

                            loadMovie(this.toload[this.loadindex],
_root.holder);
                        };
                    };
                };
            };
        .end
    .end

Everything I've been able to test works beautifully except for
_root.holder.getBytesLoaded() and _root.holder.getBytesTotal().  Both of
them always return zero.

Thanks in advance for your help.  I'm a huge fan of this project.  I've
been looking for something like this for years, and haven't found it
until now.

Richard





reply via email to

[Prev in Thread] Current Thread [Next in Thread]