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);

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s