Skip to main content
Missing Code
Inspiring
June 11, 2009
Question

Question about loader for game.

  • June 11, 2009
  • 1 reply
  • 1521 views

I made a little game with Flash/AS3, but I have never built a loader before. I don't need to load any external

files, because I added those in Flash. But what code would I write inside my program to make it load itself

and show the progress bar and all of that? Also, if I were loading external files as well: JPGs, MP3s, etc—how

would I load one of those into a symbol during the loading? I would really appreciate some help, thanks.

P.S. - I know there are loader tutorials everywhere, and I read many, but I still must be missing a key concept.

This topic has been closed for replies.

1 reply

kglad
Community Expert
Community Expert
June 11, 2009

show what you've tried that's failed.

Missing Code
Inspiring
June 12, 2009

Well, the one example I have needs 2 files. Here is the code:

var loader:Loader = new Loader();
loader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, showLoader);
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, finishedLoading);
loader.load(new URLRequest("myGame.swf"));

function showLoader(e:ProgressEvent): void {
    var percent:Number = e.bytesLoaded / e.bytesTotal;
    viewPercent.text = Math.ceil(percent*100).toString();
}

function finishedLoading(e:Event):void {
    removeChildAt(0);
    viewPercent = null;
    addChild(loader);
}

It appears to work fine and dandy, but my issue is I want to have it be only one file.

kglad
Community Expert
Community Expert
June 12, 2009

try:

this.loaderInfo.addEventListener(ProgressEvent.PROGRESS, showLoader);
this.loaderInfo.addEventListener(Event.COMPLETE, finishedLoading);


function showLoader(e:ProgressEvent):void {
    var percent:Number = e.bytesLoaded*100 / e.bytesTotal;
    viewPercent.text = Math.ceil(percent*100).toString();
}

function finishedLoading(e:Event):void {
    removeChildAt(0);
    addChild(loader);
}