开发者

AS3 Preloader Internal or External?

I was wondering what the best way to load my flash game would be. I know how to make an external preloader, but if I want to upload the .swf of the game to a site like newgrounds, Im guess开发者_开发技巧ing I need an internal preloader.

I've tried a few times but my game only displays after the swf is 100% loaded. While its loading I just see white screen with grey "..." which im guessing is built into the flash player.

I have a .fla called AsteroidsGame.fla which has a library of some classes, and the game's structure is coded into a .as file called AsteroidsGame.as. Maybe this is causing issues? I dont know, but I'd really appreciate any help getting a preloader up and running.

Thanks.


In short, when loading, the flash player will start on frame 1, and will continue to sit there until all the data on frame 1 has been loaded. Only then will it proceed to the next frame. You can get a detailed report of how many bytes of data is exported to each frame by checking the "Generate Build Report" checkbox in the "Flash" tab under "File->Publisher Settings"

To get a simple loading display going, add a TextField named "loader_txt" in frame 1, and add this code in action:

  stop();

  this.addEventListener(Event.ENTER_FRAME, loading);

  function loading(e:Event):void{

      var total:Number = this.stage.loaderInfo.bytesTotal;
      var loaded:Number = this.stage.loaderInfo.bytesLoaded;

      loader_txt.text = Math.floor((loaded/total)*100)+ "%";

    if (total == loaded){
      play();
      this.removeEventListener(Event.ENTER_FRAME, loading);
    }

  }

To make sure your assets and actionscript code are exported beyond frame 1 so above code can kick in immediately when flash movie begins to load, go to "File->Publish Settings", select "Flash" tab, and click on "Settings..." button to the right of "Script". A dialog should show up. In that dialog, under "Export classes in frame:", enter 2.

For assets in library, you may need to do similar thing. Right click on a library asset and select properties, and you'll see the option to uncheck "Export in frame 1". If you uncheck it (which means flash movie can start to play before this asset is loaded), you will have to make sure you have a reference to that symbol somewhere beyond frame 1 in the timeline, otherwise Flash will omit it from the compilation.

Good luck!


External. With the proper security permissions you should be able to load content from a remote location into a shell in most any environment.

The delay you see when loading with an internal loader is likely caused by library assets your are exporting for actionscript at runtime. They will get exported to the first frame. until that frame loads you can't see any preloading and your preloader logic will jump to the percent loaded of that first frame once it has finished exporting those assets.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜