Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6372885
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T01:17:39+00:00 2026-05-25T01:17:39+00:00

I am currently trying to implememnt a Singleton Class in order to store a

  • 0

I am currently trying to implememnt a Singleton Class in order to store a ArrayCollection of items that I can then access and manipulate across the lifecycle of my app. I have created the below Singleton Class that is designed to hold the ArrayCollection information:

package valueObjects
{
    import mx.collections.ArrayCollection;  

    [Bindable]
    public class Model
    {
        private static var instance:Model = new Model();

        public var ids:ArrayCollection = new ArrayCollection();

        public function Model()
        {
            if(instance)
            {
                trace("New instance cannot be created. Use Singleton.getInstance()");
            }
        }

        public static function getInstance():Model
        {
            return instance;
        }
    }
}

I have then created the following code on the Main Deafult page for my application so that the ArrayCollection is populated as soon as the app is initiated:

        import valueObjects.Model;          

        protected var models:Model = new Model();

                private function loop():void
        {
            var index:int;
            for( index = 0; index < compsCollection.length; index++ )
            {
                trace( "Element " + index + " is " +  compsCollection[index].comp_id );
                            models.ids.addItem(compsCollection[index].comp_id);
                trace(models.ids.length);
            }               
        }

The ArrayCollection in the Singleton Class is being populated as the trace statement that I have entered into the loop clearly shows the build of of data in the ArrayCollection. However then when I move to another view within the application I then try to access this ArrayCollection within the Singleton Class with the following code:

import valueObjects.Model;

protected var models:Model = Model.getInstance();
protected var test:ArrayCollection = new ArrayCollection();

protected function view1_viewActivateHandler(event:ViewNavigatorEvent):void
            {

                var index:int;
                trace("Array Length =" + models.ids.length);
                for( index = 0; index < models.ids.length; index++ )
                {
                    trace( "Element " + index + " is " + models.ids[index].comp_id );
                    test.addItem(models.ids[index].comp_id);
                }   
                testbox.text = test.toString(); 
            }

Now the problem I am having is that when I try to access this ArrayCollection(ids) it appears to be empty for some reason. I have included a trace statement that also says that the length of the ArrayCollection is “0”. Can anyone please help??

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T01:17:40+00:00Added an answer on May 25, 2026 at 1:17 am

    try like this

    public static function getInstance():Model
    {
        if(instance == null)
          instance= new Model();
    
        return instance;
    }
    

    here no need of assigning to variable

    protected var models:Model = Model.getInstance();
    

    use directly like

    Model.getInstance().ids = new ArrayCollection();
    

    Try this,
    this might be helpful to u.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm currently trying to implement a class to handle secure communications between instances of
I'm currently trying to implement a socket server that enables the clients to send
I've been trying to implement unit testing and currently have some code that does
I'm currently trying to implement a UITableView with a delegate and data source that
I'm currently trying to implement a StopWatch class. The interface is something like: interface
I'm currently trying to implement something that combines reverse engineering and graph theory. Therefore
I'm currently trying to implement a destroy/remove method for views but I can't get
I'm currently trying to implements a greendroid ActionBar that have a ActivityGroup below it.
We are currently trying to implement a SELECT FOR UPDATE in order to lock
I'm currently trying to implement a factory as a singleton. I practically used the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.