FDT Template
Ever built a class that extends MovieClip, which has no assets in it at compile time? But you still feel you have to place a blank MovieClip in the Flash library bound to this class?
I got sick of doing this each time I create a new MovieClip extending class, so I've taken the FDT template 'create' which normally inserts a static method for attaching your class, but relies on that blank movie and made it work without it. This method also allows you to pass Arguments directly to the constructor function, which you cannot normally do when using attachMovie etc.
An example class looks as follows:
-
class Example extends MovieClip {
-
-
function Example( arg1:String, arg2:Object )
-
{
-
// do something with the arguments...
-
}
-
-
public static function create( container:MovieClip, name:String, depth:Number, init:Object, args:Array ):Example
-
{
-
var mc:MovieClip = container.createEmptyMovieClip( name, depth );
-
if( init ) for( var i:String in init ) mc[ i ] = init[ i ];
-
mc.__proto__ = Example.prototype;
-
Function( Example ).apply( mc, args );
-
return Example( mc );
-
}
-
}
To implement that class, you would do
-
var initObject:Object = { _x: 100, _y: 200 };
-
var constructorArgs:Array = [ 'a string', { value:'a property', value2:'another property' } ];
-
var myExample:Example = Example.create( this, 'example_mc', getNextHighestDepth(), initObject, constructorArgs );
To install this template, download this XML file, open Eclipse, go to preferences > FDT > Editors > Templates, select Import... and select the unzipped XML file.
There are other methods for achieving the same effect, Peter's one is a great example.
2 Comments so far
Leave a reply
Hey this works a treat! I've been trying to do this for ages, and couldn't get peter's to work? Thankyou!
Great help, thank you very nice