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

How do I create a movie?

The Flash Basics section covered all the concepts required to start creating Flash files. Here we put some of those concepts to work to create a (very) simple movie. The steps involved are:

  1. Set the screen size and frame rate.
  2. Set the background colour.
  3. Add objects defining shapes, images, buttons, etc.
  4. Add the objects to the display list.
  5. Tell the Flash Player to display the result.
  6. Repeat steps 3 to 5 as necessary.

It can get a lot more complicated when you start adding behaviour using Actionscript but for displaying static content that is all there is to it.

try {
    Movie movie = new Movie();       

    final MovieHeader header = new MovieHeader();
    header.setFrameSize(new Bounds(0, 0, 8000, 8000));

    movie.add(new Background(WebPalette.LIGHT_BLUE.color()));

    Canvas canvas = new Canvas();
        new LineStyle1(20, WebPalette.BLACK.color()));
        new SolidFill(WebPalette.RED.color()));
    canvas.move(x - width / 2, y - height / 2);
    canvas.rline(width, 0);
    canvas.rline(0, height);
    canvas.rline(-width, 0);
    canvas.rline(0, -height);

    movie.add(Place2.show(identifier, 1, 0, 0));

} catch (CoderException e) {
} catch (IOException e) {

Movie is essentially a container class for the objects used to create a movie. The Header class is used to set the parameters that are written to the Header record when the movie is encoded. Here we set the Flash version, the size of the screen and the rate at which the movie is played. Movie will calculate the size of the file and the number of frames when the movie is encoded and set the values in the Header object.

After setting the header values, the next stage is to select a background colour for the movie. The WebPalette class defines a wide range of preset colour using the Netscape Colour Table however you can select any colour you want. If you do not specify a background colour then Flash Player will set it to white.

The next stage is to define the objects that represent the shapes, images, buttons, movie clips and sounds that are displayed in the movie. Transform contains several utilities classes that allow you to easily load sounds and images and generate the objects for displaying text and shapes. To keep the example code simple (but not very useful) we use the Canvas to draw a simple rectangle.

Once the objects you want to display are added to the movie, you can then add them to the display list. Place2 has a wide range of methods which allow you to specify coordinate and colour transforms to change the way an object appears when it is drawn (and without changing the definition).

The final part is to encode all the object and write them to a file. Transform takes care of all the steps involved in encoding the objects that make up a movie. All you have to do it be prepared to handle any errors that might occur. CoderException will be thrown is there is an error in the way an object is encoded. This is definitely a bug in the Transform code. An IOException will occur if there is an error writing the file.