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

  • Home
  • SEARCH
  • 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 6388533
In Process

The Archive Base Latest Questions

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

I want to share an Array which all classes can get and change data

  • 0

I want to share an Array which all classes can “get” and “change” data inside that array. Something like a Global array or Multi Access array. How this is possible with ActionScript 3.0 ?

  • 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-25T03:17:26+00:00Added an answer on May 25, 2026 at 3:17 am

    There are a couple of ways to solve this. One is to use a global variable (as suggested in unkiwii’s answer) but that’s not a very common approach in ActionScript. More common approaches are:

    Class variable (static variable)

    Create a class called DataModel or similar, and define an array variable on that class as static:

    public class DataModel {
        public static var myArray : Array = [];
    }
    

    You can then access this from any part in your application using DataModel.myArray. This is rarely a great solution because (like global variables) there is no way for one part of your application to know when the content of the array is modified by another part of the application. This means that even if your data entry GUI adds an object to the array, your data list GUI will not know to show the new data, unless you implement some other way of telling it to redraw.

    Singleton wrapping array

    Another way is to create a class called ArraySingleton, which wraps the actual array and provides access methods to it, and an instance of which can be accessed using the very common singleton pattern of keeping the single instance in a static variable.

    public class ArraySingleton {
        private var _array : Array;
    
        private static var _instance : ArraySingleton;
    
    
        public static function get INSTANCE() : ArraySingleton {
            if (!_instance)
                _instance = new ArraySingleton();
    
            return _instance;
        }
    
    
        public function ArraySingleton() {
            _array = [];
        }
    
    
        public function get length() : uint {
            return _array.length;
        }
    
        public function push(object : *) : void {
            _array.push(object);
        }
    
        public function itemAt(idx : uint) : * {
            return _array[idx];
        }
    }
    

    This class wraps an array, and a single instance can be accessed through ArraySingleton.INSTANCE. This means that you can do:

    var arr : ArraySingleton = ArraySingleton.INSTANCE;
    arr.push('a');
    arr.push('b');
    trace(arr.length); // traces '2'
    trace(arr.itemAt(0)); // trace 'a'
    

    The great benefit of this is that you can dispatch events when items are added or when the array is modified in any other way, so that all parts of your application can be notified of such changes. You will likely want to expand on the example above by implementing more array-like interfaces, like pop(), shift(), unshift() et c.

    Dependency injection

    A common pattern in large-scale application development is called dependency injection, and basically means that by marking your class in some way (AS3 meta-data is often used) you can signal that the framework should “inject” a reference into that class. That way, the class doesn’t need to care about where the reference is coming from, but the framework will make sure that it’s there.

    A very popular DI framework for AS3 is Robotlegs.

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

Sidebar

Related Questions

This is the URL I want to share: http://mydomain.com/#url=http://stackoverflow.com Inside my site, I do
I've a small project that I want to share with a few others on
I have a PHP page and I want to share some data between pages
Say I have the following interface that I want to share between my server
I have a single Rails 2.2.2 app that I want to 'share' with multiple
So all I simply want to do is make a Ruby program that reads
I have a result set of data that I want to write to an
I want to share an object between my servlets and my webservice (JAX-WS) by
We want to share user validation configuration between a Java validation class (for sanity
I want to share an eclipse project with the rest of my team through

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.