Some Flash preloading issues you’d better know

I never used a preloader in a game… all my games are quite light, and I used to preload movies only in some heavy website intros.
Heavy, as I said, but 100% timeline and 0% actionscript

Today, I was making a preloader for Glomb, because I am dealing with a sponsor (yes… maybe I am giving Glomb for an exclusive sponsorship) when I come into a problem.

The preloader started loading when the movie was at 99% loaded.

I don’t think the sponsor would like his logo to be shown only at the 1% of the loading time, so I was wondering what was wrong with the preloader.

This was the code, in the 1st frame:

1
2
3
4
5
6
7
8
9
stop();
onEnterFrame = function () {
	already_loaded = _root.getBytesLoaded()/_root.getBytesTotal();
	// show some fancy preloading graphics
	if (already_loaded == 1) {
		delete onEnterFrame;
		play();
	}
};

It’s a very common preloader, you may find it on a lot of tutorial sites and books.

But it did not work for me.

After a while, I solved the issue: most of the graphics and sounds in the game are not in the timeline… they are called dynamically by the actionscript with attachMovie or attachSound.

The problem is Flash compiler does not know when you are going to use those graphics and sounds, so it preloads all this stuff before the 1st frame. So when my preloader comes in action, the 99% of the movie (graphics and sounds) are loaded, then the remaining 1% (actionscript itself) is loaded showing the preloader.

This happens because you have this checkbox enabled

This checkbox determines the object must be loade before the 1st frame.

Never mind! Just uncheck it and everything will work fine!

This is not the solution… if you uncheck the checkbox, when the compiler scans the timeline and does not find the resource, it simply ignores it and your game will be compiled without graphics/sounds.

What can you do?

If your preloader is on frame 1, you should made your game start on frame 3, and put all your dynamically created objects at frame 2. This way, the movie will compile the objects because it finds them on frame 2, but the first thing to be loaded will be the preloader, and everything will work fine. Obviously, the Export in first frame mark has to be unchecked.

Rate this post: 1 Star2 Stars3 Stars4 Stars5 Stars (4 votes, average: 4.50 out of 5)
Loading ... Loading ...
Flash Templates provided by Template Monster are pre-made web design products developed using Flash technology.
They can be easily customized to meet the unique requirements of your project.
Be my fan on Facebook and follow me on Twitter! Exclusive content for my Facebook fans and Twitter followers

This post has 13 comments

  1. colplayer

    on February 3, 2008 at 1:23 am

    hey, nice job u’ve put here.I’ve got some of a nasty situation so i want to ask u HOW TO PUT A SWF FILE IN A WORDPRESS HEADER. It will really be great if u can help me. u’ve got my email there. u can write.10x very much

  2. Faisal

    on February 3, 2008 at 3:31 am

    I think I used that preloader before. But thanks for the heads up!

    P.S. I sent you an e-mail, did you see it?

  3. wildwobby

    on February 3, 2008 at 3:40 am

    Cool tip, I never would have been able to figure that one out? Are the forums coming soon btw?

  4. Frederik J

    on February 3, 2008 at 8:49 am

    Nice. Looking forward to see the sponsorship.

  5. abhilash

    on February 3, 2008 at 10:41 am

    i don’t think this is useful for me becoze i don’t attach movie clips, but this will be useful for others.
    what about your line rider tutorials, u wrote the last one in mid 2007 from then i am waiting for those tutorials…..

  6. Lachy

    on February 3, 2008 at 1:29 pm

    Hey,

    I filed a lookover on the warning about entering the page with the stop badware site and they seem to have taken it down, so i hope im responsible for getting it done because you deserve that for this blog :)

    Thanks

  7. nathan hunt

    on February 3, 2008 at 3:32 pm

    hi

  8. Andre

    on February 4, 2008 at 1:39 am

    I had this issue with one of my earlier games that didn’t have mochiads

  9. Shadow Scythe

    on February 4, 2008 at 4:30 am

    This is a very very very very useful thing that I will keep in mind immediately because I do believe you’ve solved a very annoying problem in one of my in-progress games. Thanks vera much!

  10. Artus

    on February 28, 2008 at 2:40 am

    Man you are great:) i have bet looking for this for ages and you told me hove to do this.:)
    i allways use loadMovie() as preloader and it stinks:D this is beter one. Thx man.

  11. brart

    on April 28, 2008 at 11:39 am

    how do you preload the attachSound() things?

  12. twyud

    on August 13, 2008 at 3:56 pm

    oh thank’s man, that’s good tutor

  13. Jens Picks

    on March 21, 2010 at 6:35 am

    How to attach preloader swf intro before people gets in main page ?