AS3 反射加载类

import flash.display.Sprite;       

import flash.display.MovieClip;   

import flash.utils.getDefinitionByName;   



for (var i=1; i<=2; i++)

{

    var ClassReference:Class = getDefinitionByName("MyMC"+i) as Class;

    var instance:MovieClip = new ClassReference();

    instance.x=i*200;

    addChild(instance);

}

getDefinitionByName后面跟的就是类名,反射加载的好处可以方便加载接近命名的类,不过反射加载性能很差,一般应该只用于初始化时加载

你可能感兴趣的:(as3)