开发者

Use a Global ArrayCollection in Flash Builder Mobile application?

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


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.


Or easiest way is make array static.

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

but for this case is Singleton way better.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜