Hi guys, I'm having issues with my preloader and I simply cannot see the issue with it. It's the exact same code I've been using for all my previous projects and yet it's suddenly stopped working. Hoping a fresh set of eyes will be able to spot the problem. The code appears to run fine when I am debugging my game (CMD + Return) but if I run the swf file in Flash (using simulate download) to test the loading bar it doesn't move at all, just sits at the lowest point even though the game is in fact loading. In my settings everything (except the preloader) is set to export in frame 2, my preloader is in frame 1, and the "afterItemsLoaded" label takes you to frame 3.
Here's an extract of the the document class (that calls the preloader):
public dynamic class Engine extends MovieClip
{
private var _preloader:Preloader;
private var _gameLayer:MovieClip;
private var _mainMenu:MainMenu;
public function Engine()
{
trace("Starting up Engine");
this.focusRect = false;
addEventListener(Event.ADDED_TO_STAGE, startEverything);
}
private function startEverything(e:Event):void
{
removeEventListener(Event.ADDED_TO_STAGE, startEverything);
var isOnCorrectSite:Boolean = checkURL();
trace("isOnCorrectSite = " + isOnCorrectSite.toString());
if(isOnCorrectSite)
{
_preloader = myPreloader;
_preloader.begin(this.loaderInfo);
_preloader.addEventListener("loadComplete", loadAssets);
_preloader.addEventListener("preloaderFinished", loadComplete);
}
else
{
gotoAndStop(1);
myPreloader.alpha = 0;
}
}
}
I think that's all the important bits from that, and the preloader code is:
public class Preloader extends MovieClip
{
public var _ldrInfo:LoaderInfo;
public function Preloader():void
{
trace("New preloader created");
}
public function begin(ldrInfo:LoaderInfo = null):void
{
trace("Beginning load");
this._ldrInfo = ldrInfo;
addEventListener(Event.ENTER_FRAME, checkLoad);
}
private function checkLoad(e:Event):void
{
if (_ldrInfo.bytesLoaded == _ldrInfo.bytesTotal && _ldrInfo.bytesTotal != 0)
{
//loading complete
trace("Load complete");
dispatchEvent(new Event("loadComplete"));
phaseOut();
}
updateLoader(Math.floor(_ldrInfo.bytesLoaded / _ldrInfo.bytesTotal));
}
private function updateLoader(num:uint):void
{
//num is a number between 0 and 1
//e.g. mcPreloaderBar.width = num * fullWidth;
this.loadBar.width = 10 + 290*num;
trace("Updating loader, num: " + num + " so width will be: " + this.loadBar.width);
}
private function phaseOut() : void
{
trace("phaseOut called");
removeEventListener(Event.ENTER_FRAME, checkLoad);
phaseComplete();
}
private function phaseComplete() : void
{
trace("phaseComplete called");
dispatchEvent(new Event("preloaderFinished"));
}
}
"New Preloader created" and "Beginning load" appear in the output, but nothing after that :/
Sorry, I wasn't clear. The inital Engine trace statements "Starting up Engine" and whether or not it is on an approved site are appearing, followed by the first 2 preloader statements. After that, nothing, unless I am running in debug mode in which case everything appears fine.
The Engine class is the document class for the project, so I assume it must be being exported in frame 1.
what are the first few (or the final, if the output remains the same) trace output lines using:
private function checkLoad(e:Event):void
{
trace(_ldrInfo.bytesLoaded,_ldrInfo.byteTotal);
if (_ldrInfo.bytesLoaded == _ldrInfo.bytesTotal && _ldrInfo.bytesTotal != 0)
{
//loading complete
trace("Load complete");
dispatchEvent(new Event("loadComplete"));
phaseOut();
}
Nothing. I'm getting no trace statements whatsoever from the checkLoad function, or anything after that, unless I hit CMD + ENTER to build and debug immediately. The game continues to work fine after it has loaded, but no more trace outputs appear at all.
"Beginning load" is the last output I get from the game.
Unfortunately I don't have access to a server just now, which is why I have been using 'simulate download,' but I have previously tried uploading the game to Flash Game License and the same thing happened. Loading bar froze and didn't update, but the game still loaded in the background anyway.
what's the trace output from:
public function begin(ldrInfo:LoaderInfo = null):void
{
trace("Beginning load");
this._ldrInfo = ldrInfo;
var t:Timer=new Timer(1000,10);
t.addEventListener(TimerEvent.TIMER,traceF); // <- import the timer (flash.utils) and timerevent (flash.events)
addEventListener(Event.ENTER_FRAME, checkLoad);
trace("added",this.hasEventListener(Event.ENTER_FRAME));
}
private function traceF(e:TimerEvent):void{
trace(this.hasEventListener(Event.ENTER_FRAME));
}
I got the "added true" output for the first trace you suggested adding but nothing else. (And yes, I did remember to call start() on the timer, t, and declare it as a class variable to ensure it didn't get lost).
This is really weird. I've never had issues like this with Flash before, and it is the same preloader I've always used :/
North America
Europe, Middle East and Africa
Asia Pacific