Archive for the 'ActionScript 2.0' Category
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.
Open Source Library
I'm currently putting together a library for release under a GPL license. It will include animation management classes, a core kernel and threading engine to remove the reliance on onEnterFrame events, and a debugging tool.
This lib is aimed at Flash Developers who predominantly work on animation intensive sites, rather than application development.
XML Cache class
This is a class that I wrote quite a while back. It works just like Flash's XML Class, but if you try and load the same file / URL again, it will use the XML data stored in memory rather than reconnecting to the server.
Example:
-
import com.pixelbreaker.utils.XMLCache;
-
-
myXML = new XMLCache();
-
myXML.load( 'anXMLfile.xml' ); // will load the file in
-
-
myXML2 = new XMLCache();
-
myXML2.load( 'anXMLfile.xml' ); // will use previously loaded data.
The idea is simple, the XMLCache class extends XML, and has a static object called xmlCache, whenever an XML file is loaded, it's stored in the static object with the name exactly representative of the full filename/path passed to the load() method, then whenever it's called again, the data is pulled from the static object. Easy peasy!