为什么这个 ActionScript 程序不工作?
它向我显示错误:
1120:访问未定义的属性 myArray。 DataGrid.mxml /DataGrid/src 第 10 行
源代码:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" minWidth="955" minHeight="600">
<mx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
[Bindable]
public var myArray:Array = new Array();
myArray[0] = "Tom"; // string
[Bindable]
public var arrColl:ArrayCollection = new ArrayCollection(myArray);
]]>
</mx:Script>
<mx:AdvancedDataGrid id="ad"
columns="{myArray}"
dataProvider="{arrColl}"/>
</mx:Application>
有什么问题?
It shows me an error of :
1120: Access of undefined property myArray. DataGrid.mxml /DataGrid/src line 10
Source Code :
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" minWidth="955" minHeight="600">
<mx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
[Bindable]
public var myArray:Array = new Array();
myArray[0] = "Tom"; // string
[Bindable]
public var arrColl:ArrayCollection = new ArrayCollection(myArray);
]]>
</mx:Script>
<mx:AdvancedDataGrid id="ad"
columns="{myArray}"
dataProvider="{arrColl}"/>
</mx:Application>
What is the problem ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
除非您确切知道自己在做什么,否则不应直接在脚本块中编写任意代码。相反,您应该这样做:
此代码的另一个问题是
myArray[0] = "Tom"
不会导致数据网格更新。为此,您必须分配给变量myArray
本身(例如myArray = ["Tom"]
)。You shouldn’t write arbitrary code directly in a script block like that unless you know exactly what you’re doing. Rather, you should do something like this:
Another problem with this code is that
myArray[0] = "Tom"
will not cause the data grid to be updated. For that, you would have to assign to the variablemyArray
itself (e.g.myArray = ["Tom"]
).您无法开始为类定义中的数组赋值。您需要将
myArray[0] = "Tom";
行移到方法内部。如果您希望它在初始化时发生,请在应用程序标记creationComplete="yourEventHandler"
中指定一个事件处理程序,并将该行放入yourEventHandler()
中。希望有帮助,如果您需要更多代码,请告诉我:)You can't start assigning values to the array in the class definition. You need move your
myArray[0] = "Tom";
line inside of a method. If you want it to be happen at initialization, then specify an event handler in the Application tagcreationComplete="yourEventHandler"
, and put the line inyourEventHandler()
. Hope that helps, let me know if you need more code :)