Reflection mechanism in as

reflection method in actionscript:

//refelction method
  protected function getDisplayObjectInstance(skin:Object):DisplayObject{
   var classDef:Object;
   if(skin is Class){
    return new skin() as DisplayObject;
   }else if(skin is DisplayObject){
    (skin as DisplayObject).x = 0;
    (skin as DisplayObject).y = 0;
    return skin as DisplayObject;
   }
   try{
    classDef = getDefinitionByName(skin.toString());
   }catch(e:Error){
    try{
     classDef = loaderInfo.applicationDomain.getDefinition(skin.toString()) as Object;
    }catch(e:Error){
     //nothing
    }
   }
   if(classDef == null){
    return null;
   }else{
    return new classDef() as DisplayObject;
   }
   
  } 

你可能感兴趣的:(actionscript)