View Full Version : How do I get the preloader to come up immediately?
pajhonka
04-11-2007, 03:08 PM
Hello,
I'm designing a site and I'm having a problem getting the preloader to come up immediately when the user visits the site. It shows up a few seconds after the HTML loads with a beginning percentage of 60%. I've followed tutorials before about putting instances of everything into frame 2, which is skipped after the preloader is done loading. Are there any other methods out there? I can't get it to work.
Thanks,
Kevin
jcodec
04-12-2007, 09:00 PM
The fastest way to get a preloader up is to make your preloader and your primary content two different SWFs. Make sure your preloader SWF has as little content in it as possible (no bitmaps if possible, bare minimum code, few tweens, etc) to make it appear immediately. Then have the preloader SWF load the main content into a container MovieClip.
If you have a large or complex project this may be too much of a pain to undertake late in the game but for future porjects you may want to consider it from the start. It will also help you create more structured, encapsulated projects by making _root unavailable (trust me, this is a good thing).
pajhonka
04-13-2007, 01:48 AM
The fastest way to get a preloader up is to make your preloader and your pimary content two different SWFs. Make sure your preloader SWF has as little content in it as possible (no bitmaps if possible, bare minimum code, few tweens, etc) to make it appear immediately. Then have the
preloader SWF load the main content into a container MovieClip.
If you have a large or complex project this may be too much of a pain to undertake late in the game but for future porjects you may want to consider it from the start. It will also help you create more structured, encapsulated projects by making _root unavailable (trust me, this is a good thing).
Thanks for the reply! Can you tell me some of the ways omitting _root in my Actionscript will help? The reason I ask is I usually declare all my functions in frame one of the main SWF and refer to them with _root.
I'm planning a site for a client who wants a cool preloader...I should be able to do all-vector images, but I don't think I can avoid the tweens :confused:
jcodec
04-13-2007, 05:43 PM
Can you tell me some of the ways omitting _root in my Actionscript will help? The reason I ask is I usually declare all my functions in frame one of the main SWF and refer to them with _root.
Well, we've gotten off the topic of this forum a little bit now but in the interest of satisfying your question here I'll address your question here.
You're off to a good start by declaring all your functions in one frame of the main SWF! That's already a terrific practice. You just need to add one step to make your code a lot more robust - remove global qualifiers. I'll tell you why.
Imagine this scenario: you build a site, using references to _root here and there. Everything works fine. Now your client tells you that your project needs to appear inside of some kind of shell. Suddenly all your code breaks because your references to _root are no longer accurate! "What happened?" you ask. Well, now _root refers to the root of the shell SWF, not the timeline you intended!
"How do I fix this problem?" you ask yourself. Well, instead of using _root (or _global - even worse!) make your functions path directly to the timeline with _parent (or _parent._parent, etc. until you get to your destination). This may look messy on deeply nested MovieClips so you can create a shortcut to your main timeline. Examine the follwing example.
Before:
_root.myUsefulFunction(someVariable);
_root.myOtherUsefulFunction(someOtherVariable);
After:
var codeBase:MovieClip = this._parent._parent;
codeBase.myUsefulFunction(someVariable);
codeBase.myOtherUsefulFunction(someOtherVariable);
Now your code will work whether your SWF is run on its own or loaded into some other SWF shell. You have taken the first steps toward "encapsulating" your code.
pajhonka
04-14-2007, 04:58 AM
Thank you very much jcodec! I will implement this technique in my next Flash site. :D
|
vBulletin® v3.8.4, Copyright ©2000-2009, Jelsoft Enterprises Ltd.