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 maple软件,用solve求反函数出现rootof,怎么办?
    • ¥50 汇编语言除法溢出问题
    • ¥65 C++实现删除N个数据列表共有的元素
    • ¥15 Visual Studio问题
    • ¥15 state显示变量是字符串形式,但是仍然红色,无法引用,并显示类型不匹配
    • ¥20 求一个html代码,有偿
    • ¥100 关于使用MATLAB中copularnd函数的问题
    • ¥20 在虚拟机的pycharm上
    • ¥15 jupyterthemes 设置完毕后没有效果
    • ¥15 matlab图像高斯低通滤波