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:

Actionscript:
  1. class Example extends MovieClip {
  2.  
  3.     function Example( arg1:String, arg2:Object )
  4.     {
  5.         // do something with the arguments...
  6.     }
  7.  
  8.     public static function create( container:MovieClip, name:String, depth:Number, init:Object, args:Array ):Example
  9.     {
  10.         var mc:MovieClip = container.createEmptyMovieClip( name, depth );
  11.         if( init ) for( var i:String in init ) mc[ i ] = init[ i ];
  12.         mc.__proto__ = Example.prototype;
  13.         Function( Example ).apply( mc, args );
  14.         return Example( mc );
  15.     }
  16. }

To implement that class, you would do

Actionscript:
  1. var initObject:Object = { _x: 100, _y: 200 };
  2. var constructorArgs:Array = [ 'a string', { value:'a property', value2:'another property' } ];
  3. 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

  1. mjqtreble / February 16th, 2007 5:23 pm

    Hey this works a treat! I've been trying to do this for ages, and couldn't get peter's to work? Thankyou!

  2. Derya Baykal / March 30th, 2008 11:54 am

    Great help, thank you very nice

Leave a reply

*
To prove that you're not a bot, enter this code
Anti-Spam Image