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:

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.

Get the most popular Phaser 3 book

Through 202 pages, 32 source code examples and an Android Studio project you will learn how to build cross platform HTML5 games and create a complete game along the way.

Get the book

215 GAME PROTOTYPES EXPLAINED WITH SOURCE CODE
// 1+2=3
// 100 rounds
// 10000000
// 2 Cars
// 2048
// A Blocky Christmas
// A Jumping Block
// A Life of Logic
// Angry Birds
// Angry Birds Space
// Artillery
// Astro-PANIC!
// Avoider
// Back to Square One
// Ball Game
// Ball vs Ball
// Ball: Revamped
// Balloon Invasion
// BallPusher
// Ballz
// Bar Balance
// Bejeweled
// Biggification
// Block it
// Blockage
// Bloons
// Boids
// Bombuzal
// Boom Dots
// Bouncing Ball
// Bouncing Ball 2
// Bouncy Light
// BoxHead
// Breakout
// Bricks
// Bubble Chaos
// Bubbles 2
// Card Game
// Castle Ramble
// Chronotron
// Circle Chain
// Circle Path
// Circle Race
// Circular endless runner
// Cirplosion
// CLOCKS - The Game
// Color Hit
// Color Jump
// ColorFill
// Columns
// Concentration
// Crossy Road
// Crush the Castle
// Cube Jump
// CubesOut
// Dash N Blast
// Dashy Panda
// Deflection
// Diamond Digger Saga
// Don't touch the spikes
// Dots
// Down The Mountain
// Drag and Match
// Draw Game
// Drop Wizard
// DROP'd
// Dudeski
// Dungeon Raid
// Educational Game
// Elasticity
// Endless Runner
// Erase Box
// Eskiv
// Farm Heroes Saga
// Filler
// Flappy Bird
// Fling
// Flipping Legend
// Floaty Light
// Fuse Ballz
// GearTaker
// Gem Sweeper
// Globe
// Goat Rider
// Gold Miner
// Grindstone
// GuessNext
// Helicopter
// Hero Emblems
// Hero Slide
// Hexagonal Tiles
// HookPod
// Hop Hop Hop Underwater
// Horizontal Endless Runner
// Hundreds
// Hungry Hero
// Hurry it's Christmas
// InkTd
// Iromeku
// Jet Set Willy
// Jigsaw Game
// Knife Hit
// Knightfall
// Legends of Runeterra
// Lep's World
// Line Rider
// Lumines
// Magick
// MagOrMin
// Mass Attack
// Math Game
// Maze
// Meeblings
// Memdot
// Metro Siberia Underground
// Mike Dangers
// Mikey Hooks
// Nano War
// Nodes
// o:anquan
// One Button Game
// One Tap RPG
// Ononmin
// Pacco
// Perfect Square!
// Perfectionism
// Phyballs
// Pixel Purge
// PixelField
// Planet Revenge
// Plants Vs Zombies
// Platform
// Platform game
// Plus+Plus
// Pocket Snap
// Poker
// Pool
// Pop the Lock
// Pop to Save
// Poux
// Pudi
// Pumpkin Story
// Puppet Bird
// Pyramids of Ra
// qomp
// Quick Switch
// Racing
// Radical
// Rebuild Chile
// Renju
// Rise Above
// Risky Road
// Roguelike
// Roly Poly
// Run Around
// Rush Hour
// SameGame
// SamePhysics
// Save the Totem
// Security
// Serious Scramblers
// Shrink it
// Sling
// Slingy
// Snowflakes
// Sokoban
// Space Checkers
// Space is Key
// Spellfall
// Spinny Gun
// Splitter
// Spring Ninja
// Sproing
// Stabilize!
// Stack
// Stairs
// Stick Hero
// String Avoider
// Stringy
// Sudoku
// Super Mario Bros
// Surfingers
// Survival Horror
// Talesworth Adventure
// Tetris
// The Impossible Line
// The Moops - Combos of Joy
// The Next Arrow
// Threes
// Tic Tac Toe
// Timberman
// Tiny Wings
// Tipsy Tower
// Toony
// Totem Destroyer
// Tower Defense
// Trick Shot
// Tunnelball
// Turn
// Turnellio
// TwinSpin
// vvvvvv
// Warp Shift
// Way of an Idea
// Whack a Creep
// Wheel of Fortune
// Where's my Water
// Wish Upon a Star
// Word Game
// Wordle
// Worms
// Yanga
// Yeah Bunny
// Zhed
// zNumbers