-
FK founder & general loiterer
[disc ] Best AS3 Preloader
Im still searching for the definitive as3 preloader solution. Currently I use a "Root" class which is below. Problem is I still need my classes exported on the first frame which in some cases is a hefty 200k overhead before my preloader kicks in. I have all my assets later on in the piece. Im wondering what other and perhaps better systems are out there...
Code:
package
{
import flash.display.*;
import flash.events.*
import flash.text.TextField;
import flash.ui.*
import flash.net.*
import GameManager
import Constants
import MochiBot
public class Root extends MovieClip
{
public static var _root:MovieClip;
public var VALID_URL:Array = ["http://www.blastone.com", "http://blastone.com", "http://127.0.0.1", "http://www.markfennell.com", "http://markfennell.com", "file://"]
public var GAME_TITLE:String = "LILRACERZ"
private var maskWidth:Number
private var lb:int
private var ltl:int
private var percent:int
private var game:GameManager
public function Root()
{
_root = this;
_root.preloader.game.title.text = GAME_TITLE
maskWidth = _root.preloader.preloaderBar.bar.width
_root.preloader.preloaderBar.bar.width = 0
this.loaderInfo.addEventListener(ProgressEvent.PROGRESS, onRootLoaderProgress);
this.loaderInfo.addEventListener(Event.COMPLETE, onRootLoaderComplete);
var myContextMenu:ContextMenu = new ContextMenu();
myContextMenu.hideBuiltInItems();
var item:ContextMenuItem = new ContextMenuItem( 'A Blastone.com game' );
myContextMenu.customItems.push(item);
item.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT, this.menuItemSelectHandler);
this.contextMenu = myContextMenu;
function onRootLoaderProgress (event:ProgressEvent):void
{
lb = event.bytesLoaded;
ltl = event.bytesTotal;
percent = lb/ltl*100;
_root.preloader.percentage.text = String(percent)+"%";
_root.preloader.preloaderBar.bar.width = maskWidth * lb/ltl
}
function onRootLoaderComplete (event:Event):void
{
_root.preloader.percentage.text = "100%";
_root.preloader.preloaderBar.bar.width = maskWidth
if(percent>=100)
{
init()
}
}
function init()
{
var isValid = false
var url = _root.loaderInfo.url
//_root.gotoAndPlay("game");
for (var i=0; i< VALID_URL.length; i++)
{
if (url.indexOf(VALID_URL[i]) != -1)
{
isValid = true
break;
}
}
if (isValid)
{
playGame()
//_root.gotoAndPlay("intro"); // intro
}
else
{
_root.gotoAndPlay("bad");
}
}
MochiBot.track(this, "8b8cfa5f");
}
private function menuItemSelectHandler(event:ContextMenuEvent):void
{
var url:String = Constants.URL_MORE_GAMES
var request:URLRequest = new URLRequest( url );
try {
navigateToURL(request);
}
catch (e:Error)
{
}
}
public static function credits()
{
}
public static function submit()
{
_root.gotoAndPlay("submit");
}
public static function restart()
{
_root.gotoAndPlay("game");
}
private function playGame()
{
_root.gotoAndStop("game"); // intro
if (game)
{
removeChild(game)
game = null
}
game = new GameManager(stage)
addChild(game)
}
}
}
-
Hype over content...
If you're using Flex / FlashDevelop check my "Stolen from lots of places and shoved together" solution:
http://blog.gamingyourway.com/PermaL...a7a112ac3.aspx
Squize.
-
Senior Member
Originally Posted by Squize
and if you don't?
-
....he's amazing!!!
I'm having lots of fun with as3 at the moment. One of things I'm having most fun with is discovering workarounds that only work in flex.
-
....he's amazing!!!
http://doogog.com/actionscript-3-ext...preloader.html
This one works for me.
Just pulls in your main swf.
I found it wouldn't work using the document class, your base class has to be linked to a movieclip on the second frame.
-
Hype over content...
"and if you don't? "
Then I couldn't care less :P
Squize.
-
Senior Member
Originally Posted by lesli_felix
This looks really simple and makes sense. I'll try this next time.
Right now I have something that I can't even remember how it works, but it does
-
Heli Attack!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|