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条回答

    报告相同问题?

    悬赏问题

    • ¥30 这是哪个作者做的宝宝起名网站
    • ¥60 版本过低apk如何修改可以兼容新的安卓系统
    • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
    • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
    • ¥50 有数据,怎么用matlab求全要素生产率
    • ¥15 TI的insta-spin例程
    • ¥15 完成下列问题完成下列问题
    • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
    • ¥15 YoloV5 第三方库的版本对照问题
    • ¥15 请完成下列相关问题!