Preloader madness


(Ultima2876) #6

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!)


(Andrew) #7

This seemed to work perfectly! Thanks a bunch!


(lordmagnet) #9

The code found here was immensely helpful. I’m just curious how to add a splash screen to this. Everything I’ve tried has failed. Nothing fancy, just a .jpg in the background would be great.


(Bartłomiej Kalemba) #10

Sorry for rearchieve, but I want to load swf in browser. After loading whole swf, there is no time for loading bar, because everything is loaded.

Any idea how to preload game in browser?

I try to load small swf and then inside large swf. But i don’t have idea how to run loaded swf in FlashPunk?

I tested code from @zachwlewis and @jacobalbano


(Jacob Albano) #11

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.


(Bartłomiej Kalemba) #12

No, I run it from external server… Try this options You mentioned… Thanks! :smile: I try my game at FGL, and I must wait bout 15sek (with white screen) and then suddenly game appear…

New topic: How can I get my preloader to stop looping?


(Nate ) #13

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?

Thanks!


(Ultima2876) #14

Make sure you use a clipping mask to stop it drawing outside of the desired area. FlashPunk does this by default, whereas regular flash does not. http://stackoverflow.com/questions/21072536/as3-drawings-exceeds-stage-range


(Nate ) #15

Well it isn’t making the bar leave the window, the overall window is just massive it isn’t 640x480


(Nate ) #16

UPDATE:

I fixed it, in the Preloader class I made the following changes:

Used to be:

sw = stage.stageWidth;
sh = stage.stageHeight;
w = stage.stageWidth * 0.8;

Changed these three lines to:

sw = 640;
sh = 480;
w = sw * 0.8;

All is fine and good now! :smiley:


(Frazer Bennett Wilford) #17

I’m probably missing something simple here.

But:

ReferenceError: Error #1065: Variable Main is not defined. at global/flash.utils::getDefinitionByName()

Main.as is my extends Engine class which starts the world.


(Ultima2876) #18

Is it in a package? You have to include the package name (e.g. mine are com.kickbackgames.Main or com.lunaticpandora.Main).


(Frazer Bennett Wilford) #19

The preloader class is in the same location as the main class.


(Jacob Albano) #20

Regardless, if the main class is in a package at all, you’ll need to specify it.


(Mike Evmm) #21

I have the same problem, when calling getDefinitionByName("Worlds.Levels."+String(level.@levelClass)) unless I write out all the classes I might call before (so:

public function LevelSelect() 
{
	CalmTheFDown;
	ArcadeAssKickMan;
	SharkAttack;
	Summer;
	Songs;
}

I get the same error.


(Frazer Bennett Wilford) #22

I specify the package in all my classes, but still the same error.

How should var mainClass:Class = getDefinitionByName(“YourGameClass”)

look if my main class is in the same folder as the preloader and is called main.as??


(Mike Evmm) #23

I believe he meant you need to specify it when calling getDefinitionByName like: var mainClass:Class = getDefinitionByName("com.you.stuffToFetch.YourGameClass") even if you are calling it from within the same package as the class you want to call.


(Frazer Bennett Wilford) #24

But my package is nothing:

Like

package { … … }

is how my lowest level classes are ran


(Ultima2876) #25

If you’re using FlashDevelop, make sure you have defined a frame for main. Add -frame main Main to your compile command line in project settings (project > properties in the top menu).


(Frazer Bennett Wilford) #26

Is [Frame(factoryClass = “PreloaderMain”)]

good enough? Which compile do I use? pre-compile, or after?