I have the following sample Factory code:
createProduct(50, "Product1Class");
createProduct(5, "Product2Class");
private function createProduct(amount:uint, productClassName:String):void {
var productReference:Class;
try {
productReference = getDefinitionByName(productClassName) as Class;
for (var i:uint = 0; i < amount; i++) {
var product = new productReference() as ProductBaseClass; // throws reference error!
}
} catch (error:ReferenceError) {
throw new ReferenceError(error.message + " Have you linked a library item to this class?");
}
}
The product classes are associated with MovieClips in the Library using Export for Actionscript.
The above code works perfectly when the Product1Class and Product2Class are stored in the same directory (package) as the Document class / FLA file.
The moment I move Product1Class and Product2Class to a different package (eg: com.example.products) I get the ReferenceError. Obviously I’m also changing the package definition inside the Product classes and updating the Linkage to point to the new location.
I really don’t get this, because the library items are embedded inside the FLA, which usually automatically exposes the class.
Furthermore:
var p:Product1Class = new Product1Class("green");
works with no reference error, so it’s clearly got something to do with the classes not being in the application domain.