A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: AS3 Preloader Percentage

  1. #1
    Junior Member
    Join Date
    Feb 2009
    Posts
    8

    AS3 Preloader Percentage

    So I have been working on a website and building a preloader. The preloader is it's own swf that loads an xml and loads the swf files named in that. The current animation is a timeline based swf of just a swirling graphic that loads into the main preloader swf. My problem now is that the clients and some other people who have reviewed the website want it to display the percent so that they know where the loading process is at. I have no idea where to do this in my code now since I'm not the AS3 expert. I thought I would post my code and see if anyone could point me into the right direction. Thanks!


    Actioncript
    Code:
    package {
    	import caurina.transitions.properties.CurveModifiers;
    	import flash.display.*;	
    	import flash.events.*;
    	import flash.net.*;
    	import flash.text.*;
    	import flash.geom.*;
    	import flash.ui.*;
    	
    	import com.greensock.*; 
    	import com.greensock.plugins.*;
    	import com.greensock.easing.*;	
    
    	import com.sQrt121.utils.ContentLoader;
    	import com.sQrt121.utils.CustomEvent;
    	import com.sQrt121.utils.CustomAddress;
    	
    	public class SitePreloader extends MovieClip
    	{
    		
    					
    		// PRIVATE VARS	
    		private var nStageWidth:uint;
    		private var nStageHeight:uint;			
    		private var xml:XML;
    		private var mcLogo:MovieClip;
    		private var mcContainer:MovieClip;
    		private var nItemReadyCounter:uint;
    		private var aContent:Array;
    		
    		public function SitePreloader()
    		{
    			initialSetup()
    			addEventListener( Event.ADDED_TO_STAGE, init );	
    			addCopyright();		
    		}
    		private function initialSetup():void
    		{			
    			TweenPlugin.activate([AutoAlphaPlugin]);
    			
    			CustomAddress.doNothing();
    		}
    		private function init(e:Event):void
    		{
    			removeEventListener( Event.ADDED_TO_STAGE, init );
    		
    			stage.scaleMode		= StageScaleMode.NO_SCALE;
    			stage.align			= StageAlign.TOP_LEFT;				
    			
    			nStageWidth			= stage.stageWidth;
    			nStageHeight		= stage.stageHeight;	
    						
    						
    			this.addEventListener("LSPXML", loadedXML);
    			ContentLoader.addJob("xml", ["xml/sitepreloader.xml"], this, "LSPXML", false);		
    		}	
    	
    
    		
    		
    		// INTRO ANIMATION
    		private function introAnimation():void
    		{					
    			TweenMax.to(mcLogo, 1,{ alpha:1, ease:Cubic.easeOut } );						
    		}				
    			
    		// XML IS LOADED
    		private function loadedXML(e:CustomEvent):void
    		{
    			xml	= e.params.aContent[0];
    			
    			initLogo();				
    			initResize();	
    		}
    			
    		
    		// LOGO
    		private function initLogo():void
    		{
    			mcLogo			= new MovieClip();			
    			mcLogo.alpha	= 0;
    			this.addChild(mcLogo);
    			this.addEventListener("FLSPL", logoLoadComplete)
    			ContentLoader.addJob("content", [xml.logo[0].@path], this, "FLSPL", false);					
    		}	
    		private function logoLoadComplete(e:CustomEvent):void
    		{		
    			e.params.aContent[0].x	= -e.params.aContent[0].width / 2;
    			e.params.aContent[0].y	= -e.params.aContent[0].height / 2;
    			mcLogo.addChild(e.params.aContent[0]);		
    			
    			positionLogo();			
    			introAnimation();
    			initContainer();
    			initContentItems();		
    		}		
    		private function positionLogo():void
    		{	
    			mcLogo.x			= Math.round(nStageWidth / 2);
    			mcLogo.y			= Math.round(nStageHeight / 2);
    		}
    		
    		
    		// CONTAINER
    		private function initContainer():void
    		{
    			mcContainer			= new MovieClip();
    			this.addChildAt(mcContainer, 0);
    			
    			stage.addEventListener("ShowHiddenFooter", upContainer)
    			stage.addEventListener("HideHiddenFooter", downContainer)			
    		}
    		private function upContainer(e:CustomEvent):void
    		{
    			TweenMax.to(mcContainer, 0.5,{y:e.params.nNumber, ease:Expo.easeOut } );	
    		}
    		private function downContainer(e:Event):void
    		{
    			TweenMax.to(mcContainer, 0.5,{y:0, ease:Expo.easeOut } );
    		}
    		
    		// CONTENT ITEMS
    		private function initContentItems():void
    		{
    			var _aSrcs : Array	= new Array;			
    			
    			
    			stage.addEventListener("FLCI", startSite);			
    			aContent			= new Array();
    			
    			for (var i:uint = 0; i < xml.item.length(); i ++){_aSrcs.push (xml.item[i]);}			
    			this.addEventListener("FLSPCI", contentItemsLoaded);
    			ContentLoader.addJob("content", _aSrcs, this, "FLSPCI", false);
    		}		
    		private function contentItemsLoaded(e:CustomEvent):void
    		{	
    			for (var i:uint = 0; i < xml.item.length(); i ++)
    			{
    				aContent[i] = e.params.aContent[i];
    				aContent[i].addEventListener("CIR", itemReady)	
    				mcContainer.addChild(aContent[i]);
    			}			
    		}
    		private function itemReady(e:Event):void
    		{
    			nItemReadyCounter++;
    			if (nItemReadyCounter == xml.item.length())
    			{
    				for (var i:uint = 0; i < xml.item.length(); i ++){mcContainer.swapChildren(mcContainer.getChildAt(i), aContent[i])}						
    				stage.dispatchEvent(new Event("FLCI"));								
    			}
    		}
    		private function startSite(e:Event):void
    		{			
    			TweenMax.to(mcLogo, 1,{autoAlpha:0, ease:Expo.easeOut } );	
    		}			
    		
    		
    		
    		
    		
    		
    		
    		// RESIZE		
    		private function initResize():void
    		{
    			stage.addEventListener (Event.RESIZE, mainResizeHandler);
    		}
    		private function mainResizeHandler(e:Event):void
    		{
    			nStageWidth			= stage.stageWidth;
    			nStageHeight		= stage.stageHeight;		
    			
    			positionLogo();		
    		}	
    		
    		
    		private function addCopyright():void
    		{
    		    //Create an instance of ContextMenu in order to use it
    			var myMenu:ContextMenu = new ContextMenu();
    			myMenu.hideBuiltInItems();
    			
    			//Create your custom item as a ContextMenuItem
    			var menuItem1:ContextMenuItem = new ContextMenuItem("My Company");
    			var menuItem2:ContextMenuItem = new ContextMenuItem("Copyright © 2011");
    			var menuItem3:ContextMenuItem = new ContextMenuItem("My Blog");
    			
    			menuItem1.enabled = false;
    			menuItem2.enabled = false;
    			menuItem3.separatorBefore = true;
    			
    			menuItem3.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT, doSomething1);
    			
    			//Add your custom item to "myMenu":
    			myMenu.customItems.push(menuItem1, menuItem2, menuItem3);
    			this.contextMenu = myMenu;
    			
    			function doSomething1(e:ContextMenuEvent):void {
    				var url:String = "http://tumblr.com";
    				var request:URLRequest = new URLRequest(url);
    				navigateToURL(request, '_blank')
    			}
    		}	
    	}
    }

    The XML
    Code:
    <?xml version='1.0' encoding='UTF-8'?>
    
    <sitepreloader>	
    	
    	<logo path = "swf/loader.swf" />	
    		
    	<item>swf/background.swf</item>
    	<item>swf/music.swf</item>
    	<item>swf/sounds.swf</item>
    	<item>swf/hiddenfooter.swf</item>
    	<item>swf/fullscreen.swf</item>
    	<item>swf/footer.swf</item>
    	<item>swf/socialicons.swf</item>
    	<item>swf/logo.swf</item>
    	<item>swf/mainmenu.swf</item>
    	<item>swf/contentmanager.swf</item>
    	<item>swf/contentpreloader.swf</item>
    
    	
    	
    </sitepreloader>

  2. #2
    Senior Member cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,449
    You are using customclasses, which somebody has made. You need to ask the developer of those classes.
    - The right of the People to create Flash movies shall not be infringed. -

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