How do I create a movie?
Added: 31 Jan 2009. Working example for Java
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:
- Set the screen size and frame rate.
- Set the background colour.
- Add objects defining shapes, images, buttons, etc.
- Add the objects to the display list.
- Tell the Flash Player to display the result.
- 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
{
FSMovie movie = new FSMovie();
movie.setVersion(7);
movie.setFrameRate(1.0f);
movie.setFrameSize(new FSBounds(0, 0, 8000, 8000));
movie.add(new FSSetBackgroundColor(FSColorTable.lightblue()));
FSShapeConstructor path = new FSShapeConstructor();
path.rect(x, y, width, height);
FSDefineShape shape = path.defineShape(movie.newIdentifier());
movie.add(shape);
movie.add(new FSPlaceObject2(shape.getIdentifier(), layer, x, y));
movie.add(FSShowFrame.getInstance());
movie.encodeToFile(out);
}
catch (FSCoderException e) {
...
}
catch (IOException e) {
...
}
FSMovie is essentially a container class for the objects used to create a movie. You also use FSMovie 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. FSMovie will calculate the size of the file and the number of frames when the movie is encoded.
After setting the header values, the next stage is to select a background colour for the movie. The FSColorTable 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 FSShapeConstructor 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. FSPlaceObject2 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. FSCoderException 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.