Wednesday, July 1, 2009

Factory Implementation in Flex AS3

The closest thing i could find for implementing a simple factory in Flex is by using the getDefinitionByName function.

Usage:

import flash.utils.getDefinitionByName;
private static const basePath:String = "..path to implementation..";
private var a:SomeClassImp;
private var b:OtherClassImp;
public static function getRendrer(className:String):Object{
var classFullName:String = basePath+ className;
var objClass:Class = getDefinitionByName( classFullName ) as Class;
return new objClass();
}

Note: The classes that the factory is suppose to generate in run time have to be explicitly stated as var’s in the factory class. this is for the compiler to know to add them into the compilation product.


No comments:

Post a Comment

Please do not post spam on this blog, Spam sites will be reported to google.
thank you kindly.