Flagstone Software

Flash Concepts - Display List

The Display List controls the order in which objects are displayed on the screen. The list is divided into numbered layers which define the stacking order of object when the movie is displayed. Objects placed on a higher layer are displayed in front on an object on a lower layer. Only one object can be placed on a given layer at a time. When placed on the Display List an object is always visible (unless hidden by another or moved off the visible area of the screen) until it is explicitly removed.

Transform has classes for the three instructions used by the Flash Player to manipulate the display list:

There are also classes for the two original display list instructions, FSPlaceObject and FSRemoveObject which were superceded by the addition of FSPlaceObject2 and FSRemoveObject2 in Flash 3.

Displaying an object.

To add an object to the display list you need the unique identifier of the object and the layer number on which it will be displayed:

int layer = 1;
int x = 2000;
int y = 1600;

movie.add(new FSPlaceObject2(object.getIdentifier(), layer, x, y));
movie.add(new FSShowFrame());

Removing an object from the display list.

To remove an object from the display list so it is no longer visible you only need to the layer number on which it is displayed.

movie.add(new FSRemoveObject2(layer));
movie.add(new FSShowFrame());

Changing the way an object appears

To update an object on the display list, again, you only need the number of the layer on which it is displayed:

movie.add(new FSPlaceObject2(object.getIdentifier(), layer, x+100, y+100));
movie.add(new FSShowFrame());

In this situation using FSPlaceObject2 is simpler to use than the original FSPlaceObject instruction which needs the object's identifier and the layer number. You also needed to remove the object from the display list before adding it back again:

movie.add(new FSRemoveObject(object.getIdentifier(), layer));
movie.add(new FSPlaceObject(object.getIdentifier(), layer, x+100, y+100));
movie.add(new FSShowFrame());

Managing Layers

When creating a movie one approach is simply to build it frame by frame however this can get complicated very quickly if there are more than a small number of objects being displayed. Transform provides the FSLayer class which allows you to organise both the movie and the code used to create it. Separate FSLayer objects can be created for each object to be displayed and the methods it provides simplifies your code by avoiding the rather length process of creating the FSPlaceObject2, FSRemoveObject2 and FSShowFrame instructions directly.

FSLayer layer = new Layer(1);
 
layer.select(shape);
layer.move(x1, y1);
layer.show();
layer.move(x2, y2);
layer.show();
 
movie.add(layer.getObjects());

is equivalent to:

movie.add(shape);
movie.add(new FSPlaceObject2(shape.getIdentifier, 1, x1, y1));
movie.add(FSShowFrame.getInstance());
movie.add(new FSPlaceObject2(1, x2, y2));
movie.add(FSShowFrame.getInstance());

Each layer object creates, in effect, a separate timeline for each object so if the objects must be displayed at the same time you must use FSLayer's merge method to create a single timeline before adding the result to the movie.

FSLayer one = new Layer(1);
...
FSLayer two = new Layer(2);
...
ArrayList layers = new ArrayList();
layers.add(one);
layers.add(two);
 
movie.add(FSLayer.merge(layers));