• Keep in touch:
  • Linked In
  • Twitter
  • RSS

How do I draw shapes in a movie?

There are two options for drawing shapes using Transform. First you can draw them using the the classes that represent lines and curves:

ArrayList<ShapeRecord> list = new ArrayList<ShapeRecord>();

list.add(new ShapeStyle().setLineStyle(lineStyle)
    .setMove(-width/2, -height/2);
list.add(new Line(width, 0));
list.add(new Line(0, height));
list.add(new Line(-width, 0));
list.add(new Line(0, -height));

movie.add(new DefineShape(identifier, bounds, 
    fillStyles, lineStyles, new Shape(list)));

Alternatively you can use the Canvas class which provided a more abstract and certainly more concise API for drawing:

Canvas canvas = new Canvas();

canvas.move(-width/2, -height/2);
canvas.rline(width, 0);
canvas.rline(0, height);
canvas.rline(-width, 0);
canvas.rline(0, -height);


The Canvas also simplifies shape drawing by managing the line and fill styles used to draw the shape and tracks the current drawing point so that the bounding box that encloses the shape is correctly sized.