Archive for the ‘100 Useful Classes in AS 3.0 For Game Programming’ Category

Depth Sorting of objects – Important Classes for games in AS 3.0

December 22nd, 2011 by admin | 1 Comment | Filed in 100 Useful Classes in AS 3.0 For Game Programming, Flash AS 3.0, Flex (RIA), Games Programming

images

package
{
	/**
	 * ...
	 * @description : This Class can be used when you need to adjust depth of objects according to their heights.
	 * @author Aava Rani
	 */

	public class DepthSortingClass extends MovieClip
	{
		private var _parent:Object
		public function DepthSortingClass()
		{
			super();
		}   

		public function setSortingParent(__parent:Object):void {
			_parent = __parent
		}

		public function sortDisplayList():void {
 			var len:uint = _parent.numChildren;
			var i, j;
			for ( i = 0; i < len - 1; i++ )
			for (j = i + 1; j < len; j++)
			if ( _parent.getChildAt(i).y > _parent.getChildAt(j).y )
			_parent.swapChildrenAt( i, j ); 

		}  

	}

	}

Tags: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,

Loading SWFs in AIR- Important Classes for games in AS 3.0

December 22nd, 2011 by admin | 1 Comment | Filed in 100 Useful Classes in AS 3.0 For Game Programming, Flash AS 3.0, Flex (RIA), Games Programming

images

package
{
	import flash.display.Loader;
	import flash.display.MovieClip;
	import flash.system.ApplicationDomain;
	import flash.system.LoaderContext;

	/**
	 * ...
	 * @description : This class is for loading SWFs in AIR for Mobile app etc.
	 * @author Aava Rani
	 */
	public class SWFLoader extends MovieClip
	{
		private var loader:Loader;
		public function SWFLoader():void {
			initLoader('test.swf')
		}

		private function initLoader(__path:String):void {
			loader = new Loader();
			var appDomain:ApplicationDomain = new ApplicationDomain();
			var context:LoaderContext = new LoaderContext(false, appDomain);
			loader.load(new URLRequest(__path), context);
			loader.contentLoaderInfo.addEventListener(Event.COMPLETE, loaded);
		}
		private function loaded(event:Event):void
		{
			loader.contentLoaderInfo.removeEventListener(Event.COMPLETE, loaded);
			addChild(loader.content);
		}

	}
}

Tags: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,