Using a container for objects


It’s possible to make objects belong to a certain container.

Normally, everything you put on the screen is already contained within your stage. However, you can me some objects be contained by something else.

Here’s an example of how object are contained within your stage:
Stage with loose objects

These objects have simply been added on the stage with the addChild( object ); function.

Now comes interesting part, any object can be a container for other objects. To make it simpler to understand, consider the usage of “wrapper”, or in more abstract terms, a drawer.

For example:

tf1:TextField = new TextField();
tf2:TextField = new TextField();
tf1.name = "text 1";
tf2.name = "text 2";

container1:Sprite = new Sprite();
container2:Sprite = new Sprite();

container1.addChild(tf1);
container1.addChild(tf2);
container2.addChild(tf1);

Leave a comment