反射机制的研究
在某些情況下需要通過配置文件來獲取類名進而進行實例化。
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute"
??? creationComplete="init()">
??? <mx:Script>
??????? <![CDATA[
???????????? import flash.utils.getDefinitionByName;???????????????????
??????????? private function init():void
??????????? {????????????????
??????????????? var ins2:MyTestComponent;// custom class, this can’t be missed, if you don’t have such a sentence,??the flex can’t complie the class into swf file, then runtime error will occur,I don’t know whether there is some solution
??????????????? var obj:Object = getDefinitionByName("GCComponent.MyTestComponent"); //as Class;
???????????????? var ClassReference:Class = obj as Class;
??????????????? var ins:Object = new ClassReference();
??????????????? ins.width = 100;
??????????????? ins.height = 10;
??????????????? ins.x = 0;
??????????????? ins.y = 0;
??????????????? this.addChild(ins as UIComponent);????????
??????????? }
????????????
??????????? ]]>
??? </mx:Script>??
</mx:Application>
轉載于:https://www.cnblogs.com/Bill_Lee/archive/2011/03/08/1977618.html
總結
- 上一篇: MiaSocks发布第一个测试版
- 下一篇: HTTP Error 500.21