在 Flash Builder Mobile 应用程序中使用 Global ArrayCollection?

发布于 2024-12-01 20:48:46 字数 794 浏览 1 评论 0原文

我目前正在使用最新版本的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

鲸落 2024-12-08 20:48:46

您是否创建了 Model 类的实例?

在您想要访问它的类中,您应该执行以下操作:

var myModel : Model = new 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:

var myModel : Model = new Model();

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.

多情癖 2024-12-08 20:48:46

或者最简单的方法是使数组静态。

public static var ids:ArrayCollection = new ArrayCollection();

但对于这种情况,单例模式要好得多。

Or easiest way is make array static.

public static var ids:ArrayCollection = new ArrayCollection();

but for this case is Singleton way better.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文