AS3 Class Object?
can I use the Class datatype to make a class a property, then create new objects from that class? Like so:
class Foo{
private var ExampleClass:Class;
public function Foo(exampleClass:Class){
this.ExampleClass = exampleClass;
f开发者_开发问答or(var i:int; i<30; i++){
var exampleObject = new this.ExampleClass();
}
}
}
Try to follow the accepted naming conventions, it'll make your code easier to read...
public class Foo
{
private var exampleClass:Class;
private var numInstances:int = 30;
public function Foo(exampleClass:Class )
{
this.exampleClass = exampleClass;
initClasses();
}
private function initClasses():void
{
for(var i:int; i< numInstances ; i++)
{
var exampleObject:Object = new exampleClass();
}
}
}
精彩评论