sun11506 2014-03-13 08:28 采纳率: 0%
浏览 937

Flex4 通过反射MXML,获取MXML组件中的button信息,获取的信息为null

想通过Flex反射mxml获取组件中的自定义button信息。但是获取的button为null,但是可以获取public的属性信息。代码如下:
var _PurviewButtons:Boolean = true;
try {
trace("实例化:"+item.@type);
var _PurviewRefrence:Class = getDefinitionByName(item.@type) as Class;
}
catch(e:ReferenceError) {
_PurviewButtons = false;
trace(e);
//continue;
}
if(_PurviewButtons){
var _PurviewInstance:UIComponent = new _PurviewRefrence() as UIComponent;

var propertiesList:XMLList = describeType(_PurviewInstance).accessor.(@type=="com.fms.xx.module::PurviewButton");

for each(var propertyInfoa:XML in propertiesList){

var propertyNamea:String = propertyInfoa.@name;
trace("propertyNamea "+propertyNamea +" "+_PurviewInstance[propertyNamea]);
}

var _PurviewInstanceInfo:XML=describeType(_PurviewInstance);
var _properties:XMLList=_PurviewInstanceInfo..accessor.(@type=="com.fms.xx.module::PurviewButton");
trace("_properties:"+_properties.toXMLString());
//遍历按钮
for each(var _propertyInfo:XML in _properties){

var _propertyName:String = _propertyInfo.@name;//此处取出的为id
if(_PurviewInstance[_propertyName]!=null){
var _btnLabel:String = Button(_PurviewInstance[_propertyName]).label; //显示出来的按钮名称

//创建叶子节点--按钮节点
var _menuButton:Object = new Object();
_menuButton.id = _propertyName;
_menuButton.label = _btnLabel;
_menuButton.selected = false;
_menuButton.value = _propertyName;

//把按钮节点放入菜单项节点的子节点数组中
menuLeaf.children.push(_menuButton);
}else{
trace("按钮名称:"+_propertyName+" 为null。。。");
}

} //end of for
}
在mxml上端已经声明需要反射的mxml对象。
这个问题如何解决

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 素材场景中光线烘焙后灯光失效
    • ¥15 请教一下各位,为什么我这个没有实现模拟点击
    • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
    • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
    • ¥20 有关区间dp的问题求解
    • ¥15 多电路系统共用电源的串扰问题
    • ¥15 slam rangenet++配置
    • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
    • ¥15 ubuntu子系统密码忘记
    • ¥15 保护模式-系统加载-段寄存器