View Single Post
Unread 08-03-2012, 11:44 AM   #1
sammichofdoom
 
sammichofdoom's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2012
Posts: 1
[CODE] Registering a Class to Document Root.

In order to register a class with the root of a flash document. On frame one of your fla add some actionscript. Typically game files have a #include here. Instead do something like this:

Code:
import com.sammichofdoom.lib.RootClass.RootClass;
import com.sammichofdoom.ExampleWindow.ExampleWindow;

RootClass.Register(this, ExampleWindow);
RootClass:
Code:
/**
 * RootClass is a simple helper class to register a class to the root of a movieclip.
 * @author Sammiches
 * 
 * Example:
 * 
 * import lib.RootClass.RootClass;
 * import src.ExampleWindow.ExampleWindowBase;
 * 
 * RootClass.Register(this, ExampleWindowBase);
 */
class com.sammichofdoom.lib.RootClass.RootClass
{
	/*
	 * Register
	 * 
	 * Register applies the ctor of the supplied class to the root of the supplied movie clip.
	 * 
	 * @param pMovieClip:MovieClip - root of the movieclip, typically "this".
	 * @param pObjClass:Object -  class you wish to register to supplied movieclip.
	 */
	public static function Register(pMovieClip:MovieClip, pObjClass):Void
	{
		pMovieClip.__proto__ = Function(pObjClass).prototype;
		
		Function(pObjClass).apply(pMovieClip, null);
	}
}
sammichofdoom is offline   Reply With Quote