Powerful Printing in Flash : Page 4

Use Flash's robust printing support to add print functionality to your Flash movies or Web applications. By using off-screen movie clips and ActionScripts movie clip copying commands, effective printouts can be assembled on the fly.

by Eric Jansson

Nov 12, 2002

Page 4 of 4

Controlling the Printout Format
You still need to add the exhibit info and date to the printout. Here is one way to print a movie clip that is on the user interface: add a couple of textfields to the drawingArea clip. By default, make these fields invisible and then immediately before printing, make them visible. Right after printing, turn them off again.

This solution is not ideal because users will see an awkward flickering as the textfields appear and disappear just before and after printing. Also, in general, there is no guaruntee that Flash will send the image of the drawingArea clip to the printer at the exact moment the textfields are visible. If Flash is a fraction of a second late, they may not appear in the printout.

The solution, as I mentioned at the beginning, is to use an off-screen movie clip. Copy what is on the drawingArea clip to a movie clip outside the visible area, and print that off-screen clip. It turns out that Flash is perfectly capable of printing clips that are beyond the borders of the visible area (see Figure 3).

Create another clip called printingClip. Make it the same size as drawingClip, but keep it out of the visible area of the movie. To that clip, add a pair of TextFields at the top for the exhibit info and date. To further improve the look of the printout, you can stick in a border as well.

The print button needs to make a copy of what is on the current drawing area. To do this, change the print button handler:

printButton.onPress = function() {
// we need to make a copy of circleCount circles
for (var i = 0; i < circleCount; i++) {
// first find the circle clip on the drawing area
var drawnCircle = eval("drawingArea.circle" + i);
// create a new circle clip on the print area
printingArea.attachMovie("circle","circle" + i,i);
var printCircle = eval("printingArea.circle" + i);
// move the new circle clip to the same position as the other clip
printCircle._x = drawnCircle._x;
printCircle._y = drawnCircle._y;
// set color of the new circle clip
var drawnCircleColor = new Color(drawnCircle);
var printCircleColor = new Color(printCircle);
printCircleColor.setRGB(drawnCircleColor.getRGB());
}

The final movie includes a date field on the printout, so just before calling print(), fill in the date:

printingArea.dateField.text = new Date();

Then call print():

print(printingArea,"bframe");

There you have it! A print UI that you can customize to support your printing needs. Plus, if the client has new formatting requests, you can easily manipulate this printing interface without affecting the main UI.

Eric Jansson is the lead software engineer at ActiveInk (www.activeink.net), a developer of interactive online curriculum powered by the ActiveInk Network delivery platform. One of his focuses in recent years has been integrating Flash into Web-based applications, to which he brings his years of experience working with Java and object-oriented design. He can be reached at eric.jansson@activeink.net.