开发者

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();
           }
        }
    }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜