PDA

View Full Version : preloader: probably a basic question...


Ian Jones
09-09-2003, 02:25 PM
Hi,

I really should know the answer to this question. but I have never had to solve it yet.. until now:

How do I make a preloader movie that loads an external / additional *.swf and reports on its % loaded then when finished launches a new html page with this new *.swf already loaded?

Any help or pointers to a solution would be greatly appreciated. Thanks.

berniebernie
09-09-2003, 08:41 PM
you have to use the loadMovie and theotherflashswf.getBytesLoaded() function...

I know CG talk isn't really a flash oriented forum so you'd better check some specialized forums (I'd recommend www.kirupaforum.com or www.flashkit.com)

i found this thread for example on kirupaforum, there are hundreds of it over the same topic: http://www.kirupaforum.com/forums/showthread.php?s=&threadid=26291

Ian Jones
09-12-2003, 02:00 AM
Thx..I'lll check them out.

Aelius
09-17-2003, 12:43 PM
Okay, say you're loading an external swf called myMovie.swf into your timeline onto level1. Obviously, you'll have to load it in:

loadMovieNum ("myMovie.swf ", 1);

Now make a rectangular box which will act as your progress bar. Convert it to a movie clip, give it the instance name "marker" and give it the following script:

onClipEvent (enterFrame) {
// get size of file and amount loaded so far
movieTotal = level1.getBytesTotal();
movieLoaded = level1.getBytesLoaded();
// work out the percentage
percentLoaded = Math.round((movieLoaded/movieTotal)*100);
// scale this marker accordingly
this._xscale = percentLoaded;
// is it fully loaded?
if (percentLoaded>=100) {
// it's fully loaded - make progress bar invisible
this._visible = false;
} else {
// it's not fully loaded - make it visible
this._visible = true;
}


Likewise, if you want to load the movie into a container Movie clip, make the 'load' call from your main timeline:


loadMovie ("myMovie.swf ", "myContainer_mc");


Then (if you're using Flash MX) you could just use a callback to set your progress bar script:


marker.onEnterFrame = function() {
// get size of file and amount loaded so far
movieTotal = _parent.myContainer_mc.getBytesTotal();
movieLoaded = _parent.myContainer_mc.getBytesLoaded();
// work out the percentage
percentLoaded = Math.round((movieLoaded/movieTotal)*100);
// scale this marker accordingly
this._xscale = percentLoaded;
// is it fully loaded?
if (percentLoaded>=100) {
// it's fully loaded - make progress bar invisible
this._visible = false;
} else {
// it's not fully loaded - make it visible
this._visible = true;
};


Hopefully my syntax is all in tact, but I wrote this out quick, so apologies if it's not. The good thing about these methods is that because the preloader progress bar is continually checking, it should automatically appear when a new movie is loaded.

By using the callback method, you can use the same 'marker', and apply new enterFrame event scripts each time you load in a new movie, which will save you file size aswell.

Hope this is useful.

Added Later: Oh yeah, forgot - make sure you put in your 'gotoAndPlay ("loaded");' script in the 'if' condition. I left that bit out cos I know people like to do it different ways.

Ian Jones
09-18-2003, 06:18 AM
Hey, thx for the reply. I managed to solve my preolader problems, but your script was definitely educational. I have noticed this marker.onEnterFrame = function {}; a few times recently and it looks useful. I don't fully understand it though. How does it work and in what situations is it better than just an onclipEvent (EnterFrame) {} inside a movieclip?

I'm assuming you can call a marker.onEnterframe = function {}; from the _root timeline or inside any mc?

Aelius
09-18-2003, 10:29 AM
Yeah, you can call it from anywhere, so you could keep all your callbacks on the _root for good house keeping:

_root.myMovieClip.anotherMovieClip.theLastMovieClip.onEnterFrame = function() {
};

This is probably the best use for it, as you can keep everything on the timelines instead of having to look through movieclip instances.

It also means you can change an enterFrame event handler on the fly, without having to use another instance. As you practice with them, you'll find them more and more useful. I hardly ever use the onClipEvent method anymore.:)

Ian Jones
09-18-2003, 12:10 PM
very interesting.. thx for the tip! I can see a few new possibilites now.

CGTalk Moderation
01-16-2006, 02:00 AM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.