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

Remove movieclips from Array- Important Classes for games in AS 3.0

December 22nd, 2011 by aabhaanjan

images

[xml]
package
{

import flash.display.MovieClip;
/**
* …
* @description : This Class can be used when you need to remove all movieclips from its stored array.
* @author Aava Rani
*/
public class RemoveMovieClipsFromArrayClass extends MovieClip
{

public function RemoveMovieClipsFromArrayClass():void
{
trace(‘ Constructor called ‘);
}

public function removeAllMovieClipsFromArray(__clipArray:Array):void {
for (var __i:int = __clipArray.length – 1; __i >= 0 ; __i– ) {
removeChild(__clipArray[__i])
__clipArray.splice(__i, 1);
}
}

}

}
[/xml]

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

December 22nd, 2011 by aabhaanjan

images
[xml]
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 );

}

}

}

[/xml]

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

December 22nd, 2011 by aabhaanjan

images

[xml]
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);
}

}
}
[/xml]