0

So I have 2 files, where I want to be able to access an array from 1 file in the other.

package code {
import flash.display.DisplayObjectContainer;
import flash.display.MovieClip;
import flash.ui.Keyboard;
import code.*;

public class Init extends MovieClip {
    public var _solidObjects: Array;

    public function Init() {
        _solidObjects = [wall01, wall02, wall03, wall04];
        }
      }
    }

How would I be able to access the _solidObjects array from another class in a seperate file? Any help would be appreciated as I have been trying for a while with no success, thanks.

1 Answer 1

1

Constructors can be passed variables. For example:

First class:

package code {
  public class Init extends MovieClip {
    public var solidObjects: Array;

    public function Init() {
      solidObjects = [wall01, wall02, wall03, wall04];
    }
  }

Second class:

package code {
  public class SomeClass extends MovieClip {
    public var solidObjects: Array;

    public function SomeClass(param:Array) {
      this.solidObjects = param;
    }
  }
}

Usage context:

var initObj:Init = new Init();
var secondObject:SomeClass = new SomeClass(initObj.solidObjects);
Sign up to request clarification or add additional context in comments.

1 Comment

Great to hear it helped. Here on stackoverflow it's customary to mark the answer that solved your problem, so other users could identify it quickly and also benefit from it. It's a check mark next to the answer header. In this case, it's a single answer, it's pretty clear, but it's still nice to do it, because the answer poster gets some points. :D

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.