Flex mx:XMLList 和 fx:XMLList 之间的不同行为
将此代码放在 Flex3 项目中是有效的(请注意第六项上的启用属性):
<mx:XMLList id="items">
<menuitem label="file">
<menuitem label="file.new" data="New"/>
<menuitem label="file.saveAs" data="SaveAs"/>
<menuitem label="file.open" data="Open"/>
<menuitem label="file.close" data="Close"/>
</menuitem>
<menuitem label="business">
<menuitem label="business.add" data="AddBusiness"/>
<menuitem label="business.delete" enabled="{someproperty.selected}" data="DeleteBusiness"/>
</menuitem>
<menuitem label="help">
<menuitem label="help.about" data="About" />
</menuitem>
</mx:XMLList>
但是 fx:XMLList 无法以这种方式处理绑定。此代码给出编译错误:
<fx:XMLList id="items">
<menuitem label="file">
<menuitem label="file.new" data="New"/>
<menuitem label="file.saveAs" data="SaveAs"/>
<menuitem label="file.open" data="Open"/>
<menuitem label="file.close" data="Close"/>
</menuitem>
<menuitem label="business">
<menuitem label="business.add" data="AddBusiness"/>
<menuitem label="business.delete" enabled="{someproperty.selected}" data="DeleteBusiness"/>
</menuitem>
<menuitem label="help">
<menuitem label="help.about" data="About" />
</menuitem>
</fx:XMLList>
1120:访问未定义的属性项。
Having this code in a flex3 project worked (note the enabled property on the sixth item):
<mx:XMLList id="items">
<menuitem label="file">
<menuitem label="file.new" data="New"/>
<menuitem label="file.saveAs" data="SaveAs"/>
<menuitem label="file.open" data="Open"/>
<menuitem label="file.close" data="Close"/>
</menuitem>
<menuitem label="business">
<menuitem label="business.add" data="AddBusiness"/>
<menuitem label="business.delete" enabled="{someproperty.selected}" data="DeleteBusiness"/>
</menuitem>
<menuitem label="help">
<menuitem label="help.about" data="About" />
</menuitem>
</mx:XMLList>
However fx:XMLList can't handle binding in that way. This code gives a compilation error:
<fx:XMLList id="items">
<menuitem label="file">
<menuitem label="file.new" data="New"/>
<menuitem label="file.saveAs" data="SaveAs"/>
<menuitem label="file.open" data="Open"/>
<menuitem label="file.close" data="Close"/>
</menuitem>
<menuitem label="business">
<menuitem label="business.add" data="AddBusiness"/>
<menuitem label="business.delete" enabled="{someproperty.selected}" data="DeleteBusiness"/>
</menuitem>
<menuitem label="help">
<menuitem label="help.about" data="About" />
</menuitem>
</fx:XMLList>
1120: Access of undefined property items.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我想您正在严格模式下编译您的项目,并且您正在使用 items XMLList 直接作为某些组件的
dataProvider
(至少这是我发现的唯一方法)重现问题),如下所示:这会重现您提到的相同错误(#1120)。为了解决这个问题,您必须在
块中在其容器之前声明 XMLList(在示例中它是一个List
)。这样,您就可以确保 items 引用在创建容器之前存在,这是严格模式在编译期间验证的内容。更新:如果您没有启用编译器的严格模式选项,这也会生成 #1120 错误。只需在
块中声明 XMLList 即可正常工作。I suppose you are compiling your project in strict mode and that you are using the items XMLList directly as
dataProvider
for some component (at least it was the only way I've found to reproduce the problem), like this:This reproduces the same error (#1120) you mentioned. In order to fix this, you have to declare the XMLList prior to its container (in the example it's a
List
), in the<fx:Declarations>
block. This way you are assuring that the items reference will exist before the container is created, which is what strict mode verifies during compilation.Update: This will also generate the #1120 error if you don't have the compiler's strict mode option enabled. Just declare the XMLList in the
<fx:Declarations>
block and it should work fine.