I’m coding my first full fledged game, and I’m trying to add a small preloader. I tried implementing some classes I found online, but I don’t seem to grasp the concept behind it, so it has never worked so far.
Is there a simple way to implement a basic one? I am looking for the most basic of examples, so I can start building it from there.
Here is the preloader I use for all my projects. It should be pretty simple to make it work for yours. I probably don’t entirely understand all of what makes it work, but I’d be happy to help troubleshoot if it gives you trouble.
@jacobalbano I’ve stripped your preloader to the bare minimum to preload. This should be much easier to digest (not that yours wasn’t).
public class Preloader extends MovieClip
public function Preloader()
public function onEnterFrame(e:Event):void
if (loaderInfo.bytesLoaded >= loaderInfo.bytesTotal)
// If all bytes are loaded, start the game.
// Update your screen to display whatever you'd like.
private function startup():void
var mainClass:Class = getDefinitionByName("YourGameClass") as Class;
parent.addChild(new mainClass as DisplayObject);
Hi there, I tried Zach’s code and it seemed fine at first, but while it worked in Firefox and other browsers, it didn’t work in Chrome! It just sat at an empty bar… FOREVER! The game loaded fine in Chrome without a preloader though, it just took a while.
Does anyone know why this happened or have a fix? A preloader is pretty much all my game needs!
Chrome has problems accessing this variable most of the time and reports it as either 0 or infinity. The best thing is to encode the size of the swf in bytes directly into your preloader class and use that instead:
private var TOTAL_BYTES: int = 4000000; //4mb swf
The way I do it is to right click the release build swf file to get the size in bytes, then take a little bit off (this means it will fill the bar a little before the swf is fully loaded but this isn’t usually an issue and is much less annoying than the bar never quite getting full - just remember not to overdraw your bar!).
Other people have mentioned getting the value from ‘flashvars’ etc but that is something I don’t know a lot about.
Make sure you remember to update BYTES_TOTAL for every different build you do! (when you change art assets etc - it’s only really worth setting it when you’re getting ready to upload the game!)
Are you running the swf locally? If so, the loading will be so fast you won’t see the bar at all. You’ll have to upload it to your website or a Flash portal like Newgrounds or Kongregate if you want to test the loading time.
As for the second part, are you trying to load the swf as a movieclip asset? If so, that should go in a new topic.
Sorry for digging up an old thread! I have implemented this, both with Zach’s code as well as Jacob’s! I used Zach’s code to understand it and Jacobs code to add the fancy loading bar. My question is, although I am stating in the Preloader class 640x480 the preloader takes up the entire browser window, then once the game loads the game is 640x480. Any thoughts guys?