0

I am going to simplify my question. I need to create a list of vars that have defaults but they can change with clicks etc. Default Vars stored in (defaultVars.as)

These default vars are created in this class that is loaded via the main.as class. I have another class (getVars.as) that needs to access the vars that are changing. How can this new class have access to dynamic vars?

Thanks

Papa De Beau
  • 3,744
  • 18
  • 79
  • 137

1 Answers1

1

If you have your class that holds these variables instantiated in the Main class, you can pass reference to it to the constructor of the secondary class that you want to have access its properties.

Small example:

The class holding variables:

class AppModel
{
    public var test:int = 10;
    public var something:String = "hello";
}

The class needing access to those variables:

class Component
{
    public function Component(appModel:AppModel)
    {
        appModel.something = "changed";
        trace(appModel.test); // 10
    }
}

And the main class:

class Application
{
    private var _appModel:AppModel;
    private var _component:Component;

    public function Application()
    {
        _appModel = new AppModel();
        _component = new Component(_appModel);

        trace(_appModel.something); // changed
    }
}
Marty
  • 39,033
  • 19
  • 93
  • 162
  • ok, I changed it up a bit. How do I access a function on the Main.as from defaultVars.as? Thanks Marty so much. – Papa De Beau Nov 18 '13 at 16:18
  • I asked a new question here: http://stackoverflow.com/questions/20053393/as3-calling-a-function-in-main-as-document-class-from-another-class – Papa De Beau Nov 18 '13 at 17:38