A Flash Developer Resource Site

Results 1 to 8 of 8

Thread: [disc ] Best AS3 Preloader

  1. #1
    FK founder & general loiterer Flashkit's Avatar
    Join Date
    Feb 2000
    Location
    Sydney
    Posts
    1,149

    [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)
    		}
    	}
    }
    Regards Mark Fennell - Flash Kit Founder, general loiterer
    -------------------------------
    I Hate Zombies - iPhone Game | markfennell.com

  2. #2
    Hype over content... Squize's Avatar
    Join Date
    Apr 2001
    Location
    Lost forever in a happy crowd...
    Posts
    5,926
    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.

  3. #3
    Senior Member Boombanguk's Avatar
    Join Date
    Jun 2000
    Posts
    1,194
    Quote Originally Posted by Squize
    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.
    and if you don't?
    FlashGameMaker.com - er..where I say stuff.

  4. #4
    ....he's amazing!!! lesli_felix's Avatar
    Join Date
    Nov 2000
    Location
    London UK
    Posts
    1,506
    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.

  5. #5
    ....he's amazing!!! lesli_felix's Avatar
    Join Date
    Nov 2000
    Location
    London UK
    Posts
    1,506
    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.

  6. #6
    Hype over content... Squize's Avatar
    Join Date
    Apr 2001
    Location
    Lost forever in a happy crowd...
    Posts
    5,926
    "and if you don't? "

    Then I couldn't care less :P

    Squize.

  7. #7
    Senior Member hatu's Avatar
    Join Date
    Jan 2007
    Posts
    480
    Quote Originally Posted by lesli_felix
    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.
    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
    http://hatu.biz
    Portfolio & games

  8. #8
    Heli Attack! iopred's Avatar
    Join Date
    Jun 2003
    Location
    Sydney, Australia
    Posts
    923
    Christopher Rhodes
    squarecircleco.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center