将 Xml 值分配给动态创建的组件
xml 值存储在“arr”数组集合中。根据存储的数组的长度,创建下面描述的组件并将这些值动态分配给相关组件。
例如:
AdvanceSearch.mxml 是一个组件,另一个组件是 advanceSearchAtom.mxml。 “advanceSearchAtom”内有一些子组件,如文本框、组合框等。我们可以在'AdvanceSearch.mxml'中添加许多advanceSearchAtom.mxml。
var container : AdvanceSearch;
var adv : advanceSearchAtom;
for(var i:int=0;i<arr.length;i++) {
adv = new advanceSearchAtom();
adv.field.text = arr[i].field;
adv.value.selectedIndex = arr[i].value;
container.addChild(adv);
}
如果有人遇到此类问题,请告诉我。是否有明显的相关链接。提前致谢
xml values are stored in 'arr' array collection. depending on the length of the array stored, the below described components are created and assign those values to relevant components dynamically.
For Example:
AdvanceSearch.mxml is one component, and another components as advanceSearchAtom.mxml. within 'advanceSearchAtom' has some sub components as textbox, combo box etc,. we can add many advanceSearchAtom.mxml inside 'AdvanceSearch.mxml'.
var container : AdvanceSearch;
var adv : advanceSearchAtom;
for(var i:int=0;i<arr.length;i++) {
adv = new advanceSearchAtom();
adv.field.text = arr[i].field;
adv.value.selectedIndex = arr[i].value;
container.addChild(adv);
}
Please let me know if anybody come across this type of problem. if any relevant link is appreciable. Thanks in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您没有提到它,但我想问题是您在以下几行中收到空引用错误(1009):
我对吗?
这是因为
field
和value
尚未创建。根据默认的组件实例化,Flex 仅在需要时(即要显示时)创建子组件。您可以侦听
AdvanceSearchAtom
组件的creationComplete
事件并从那里更新值;或者在AdvanceSearchAtom
类中拥有Binadble
公共变量,将它们绑定到field.text
和value.selectedIndex
并分配xml 值赋给循环中的这些变量。使用创建完成:
使用数据绑定:
在AdvanceSearchAtom.mxml 内部
AdvanceSearchAtom.mxml 的脚本块中
在 AdvanceSearch 类中:
You didn't mention it, but I guess the problem is that you're getting null reference error (1009) on the following lines:
Am I right?
This is because
field
andvalue
are not yet created. As per the default component instantiation, Flex creates the children only when it is required - i.e., when it is to be displayed.You can either listen to the
creationComplete
event of theAdvanceSearchAtom
component and update the values from there; or haveBinadble
public variables in theAdvanceSearchAtom
class, bind them tofield.text
andvalue.selectedIndex
and assign xml values to those variables in the loop.Using creation complete:
Using data binding:
Inside AdvanceSearchAtom.mxml
In the script block of AdvanceSearchAtom.mxml
In the AdvanceSearch class: