back to devpro   download
/**
 * Class Instance :: Instance.as :: by Andrea Giammarchi
 * This class founds automatically unused instances for
 * your AS2.0 applications.
 * Usefull when you don't need to know an instance name
 * but you need to use one, for example, during
 * a movieclip creation .
 * __________________________________________________
 * EXAMPLE:
 * var myUniqueInstance:String = new Instance( _root ).get();
 * _root.createEmptyMovieClip( myUniqueInstance, _root.getNextHighestDepth() );
 * this.movie = _root[ myUniqueInstance ];
 * --------------------------------------------------
 * @type	ActionScript 2.0 class file
 * @version	0.1 tested
 * @author	Andrea Giammarchi
 * @date	15/02/2005
 * @lastMod 15/02/2005 09:12
 * @site	http://www.3site.it/
 */
class Instance {
	
	/** private variable */
	private var __instance:String;
	
	/**
	 * public constructor
	 * 		new Instance( path:Object )
	 * @param		Object		path where you need an unused instance name
	 */
	function Instance( path:Object ) {
		this.__instance = this.__findInstance( path );
	}
	
	/**
	 * public method
	 * 		this.get():String
	 * @return		String		an unused instance for that path
	 */
	public function get():String {
		return this.__instance;
	}
	
	/**
	 * private method
	 * 	founds an unused instance, based on Math.random() generator
	 */
	private function __findInstance( path:Object ):String {
		var __n:Number = Math.random() * 1000000000 + 1234567;
		var __s:String = new String( '__' + String( __n ).split('.').join('') + '__' );
		var __f:Boolean = false;
		for( var a in path ) {
			if( a == __s ) {
				__f = true;
			}
		}
		return __f === false ? __s : this.__findInstance( path );
	}
}
back to devpro   download
Creative Commons License