com.flagstone.transform.util.movie
Class Layer

java.lang.Object
  extended by com.flagstone.transform.util.movie.Layer

public final class Layer
extends Object

The Layer class can be used to simplify the creation of movies. It provides a series of methods that can be used to control how an object is displayed and provides an API that is easier to use when compared to creating the commands (PlaceObject, RemoveObject, etc.) used to manipulate the Flash Player's display list directly. The following code:

 Layer 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 PlaceObject2(shape.getIdentifier, 1, x1, y1));
 movie.add(ShowFrame.getInstance());
 movie.add(new PlaceObject2(1, x2, y2));
 movie.add(ShowFrame.getInstance());
 
After each set of commands the display list is updated by executing the show() method - this adds a ShowFrame instruction to the final movie which tells the Flash Player to render the display list on the screen. The select() method is only used when displaying an object for the first time or re-displaying it after it was deleted from the display list. The commands that manipulate the display list can also be combined to apply several operations at once:
 layer.select(shape);
 layer.move(x, y);
 layer.morph(0.9);
 layer.color(r, g, b);
 layer.show();
 
is equivalent to:
 CoordTransform coord = new CoordTransform(x, y);
 ColorTransform color = new ColorTransform(r, g, b);
 PlaceObject2 place = new PlaceObject2(shape.getIdentifier, 1, coord, color)
 place.setRatio(0.9);

 movie.add(shape);
 movie.add(place);
 movie.add(ShowFrame.getInstance());
 
An operation is use to set the attributes on either an PlaceObject2 or RemoveObject2 object so operations of the same type cannot be combined to create a cumulative effect. For example:
 layer.move(x1, y1);
 layer.move(x2, y2);
 
is the same as:
 layer.move(x2, y2);
 
and not:
 layer.move(x1 + x2, y1 + y2);
 
The most obvious benefit is code that is easier to write and read however the benefits of using layers come to the fore when creating movies with multiple objects. Currently the movie object represents the main time-line and the commands to control and display each object must be interleaved together. This quickly becomes unwieldy and error prone if several objects are involved. With layers, each can be regarded as the time-line for a single object. The object can then be manipulated more easily and the final set of Layers merged together to create a single time-line. The only limitation in the merging process is that all the Layers must start at the same point in time. Each Layer object created must be assigned a unique number. In Flash an object to be displayed is assigned to a given layer with (typically) only one object displayed on a given layer. The layer number is used to control the order in which the objects are displayed. Objects placed on a higher layer number are displayed in front of object placed on a lower layer number.


Constructor Summary
Layer(int number)
          Create a new Layer object.
 
Method Summary
 Layer add(Frame frame)
          Add a frame to the layer.
 List<Frame> getFrames()
          Get the list of frames.
 int getLayer()
          Get the layer number.
static List<Frame> merge(List<Layer> layers)
          Merge layers together to create a single time-line.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Layer

public Layer(int number)
Create a new Layer object. Layers are used to define the order in which objects are displayed. Objects placed on a high layer number are displayed in front of those on a lower layer.

Parameters:
number - the layer number on the display list.
Method Detail

merge

public static List<Frame> merge(List<Layer> layers)
Merge layers together to create a single time-line. Each layer is assumed to start at the same point in time. The process steps through each of the layers, frame by frame, adding all the commands used to manipulate the Flash Player's display list into a single group.

Parameters:
layers - a list of Layer objects.
Returns:
a list of all the objects contained in each layer. This list can then be added to the movie.

getLayer

public int getLayer()
Get the layer number. The Flash Player assumes that there is only one object placed on each layer and so each must have a unique number.

Returns:
the layer number.

getFrames

public List<Frame> getFrames()
Get the list of frames.

Returns:
the Frames defined for the Layer.

add

public Layer add(Frame frame)
Add a frame to the layer. The object may be selected later for display.

Parameters:
frame - a Frame object.
Returns:
this object.


Copyright © 2002-2010 Flagstone Software Ltd.. All Rights Reserved.