Skip to content

Instantly share code, notes, and snippets.

@lynxerzhang
Created November 15, 2012 05:39
Show Gist options
  • Save lynxerzhang/4076838 to your computer and use it in GitHub Desktop.
Save lynxerzhang/4076838 to your computer and use it in GitHub Desktop.
internal class 'can' be instantiated in the external context
/**
包外类和以Internal申明的类无法在外部实例化, 但一个方法可以使其在外部实例化。
将该类实例或类引用保存在外部可访问的数据结构内, 然后获取,外部定义的变量名需要以*号为类型符。
需要获取类定义的话, 可通过访问Object的constructor属性来获取从而避免通过平常方式(
getDefinitionByName)获取时产生的ReferenceError错误, 同时调用方法是需要使用数组访问符[]来
调用这些类所定义的方法
internal class InternalClassShow{
public function show():void{
trace("run");
}
}
//直接或取保存的类定义
//getClass 和 getObject为hashMap, 获取类定义和实例对象
var c:Class = getClass("InternalClassShow") as Class;
new c()["show"](); //output 'run'
var c:Class = (getObject("InternalClassShow") as Object).constructor as Class;
new c()["show"](); //output 'run'
//getDefinitionByName(getQualifiedClassName(getObject("InternalClassShow")));
//will encounter a referenceError "could not found 'InternalClassShow'"
**/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment