在 Flash Builder Mobile 应用程序中使用 Global ArrayCollection?
我目前正在使用最新版本的 Flash Builder 开发移动应用程序,我需要创建一个 Global ArrayCollection 来存储从本地数据库提取的信息。我可以很好地从数据库中提取数据,但是当我尝试时,我似乎无法访问全局变量。我有一个名为“Model.as”的以下 .as 文件,该文件位于名为 valueObjects 的文件夹中,该文件包含以下代码:
package valueObjects
{
import flash.data.SQLConnection;
import mx.collections.ArrayCollection;
public class Model
{
public var ids:ArrayCollection = new ArrayCollection();
public function Model()
{
}
}
}
现在我想开始使用数据库中的信息填充此 ArrayCollection,因此我将该类导入到默认包 mxml 文档,当应用程序启动时,将首先使用以下命令加载:
import valueObjects.Model;
然后在私有函数中,我尝试访问 ids ArrayCollection 并填充它,但是出现以下错误:
-1120: Access of undefined property ids.
-Access of undefined property ids
谁能帮忙解决这个问题?谢谢
I am currently developing a mobile application using the latest version of Flash Builder and I need to create a Global ArrayCollection to store information in that is pulled from a local DB. I can pull back the data from the DB fine however I cannot seem to access the Global variable when I try. I have the follng .as file called "Model.as" which is located in a folder called valueObjects and that file contains the following code:
package valueObjects
{
import flash.data.SQLConnection;
import mx.collections.ArrayCollection;
public class Model
{
public var ids:ArrayCollection = new ArrayCollection();
public function Model()
{
}
}
}
Now I want to start populating this ArrayCollection with the info from the database so i import the class into the Default Package mxml doc which will be loaded up first when the app starts by using:
import valueObjects.Model;
Then in a private function I try to access the ids ArrayCollection and populate it however I get the following error:
-1120: Access of undefined property ids.
-Access of undefined property ids
Can anyone please help with this?? Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您是否创建了 Model 类的实例?
在您想要访问它的类中,您应该执行以下操作:
要在类之间共享模型实例,您将需要做更多的工作。通过传递对同一对象的引用,或使用替代方法(例如创建单例)。如果您需要示例,许多 Flex 框架(例如 Cairngorm 或 RobotLegs)都使用 Singleton。
Have you created an instance of your Model class?
In the classes you want to access it, you should do something like this:
To share the model instance between classes, you're going to have to do slightly more work. Either by passing around a reference to the same object, or using an alternate method such as creating a Singleton. Many Flex frameworks, such as Cairngorm or RobotLegs, use Singletons if you need an example.
或者最简单的方法是使数组静态。
但对于这种情况,单例模式要好得多。
Or easiest way is make array static.
but for this case is Singleton way better.