Browse DevX
Sign up for e-mail newsletters from DevX


Powerful Printing in Flash MX 2004 : Page 2

ActionScript 2.0's new PrintJob class allows you to add robust printing support to your Flash-based Web applications. Learn how to use this new feature—along with a code design that allows on-the-fly interface assembly on any movie clip.




Building the Right Environment to Support AI, Machine Learning and Deep Learning

A Flash Drawing Application
This article uses the same application as the previous article, a Flash application for drawing. Take a look at the user interface in Figure 1, which contains a color selector, a tool palette, a "print" button, and a main interface where the drawing occurs.

Figure 1. The User Interface: The app's user interface contains a color selector, a tool palette, a "print" button, and a main interface where the drawing occurs.

Figure 1 shows not one, but actually three user interfaces. The interface at the top is the one the user interacts with, while the two below are hidden offscreen and used only for printing (the major movie clips are labeled with their instance names in [brackets] for easy reference). This means that the two printing interfaces are only ever visible to the user in printouts.

This is possible because Flash is not limited to printing what is on-screen; in Flash, you can create movie clips offscreen and then print those offscreen clips. The movie clip to the bottom left (printArea1) is a cover sheet for the movie clip to the bottom right (printArea2), where the user's actual drawing is printed. This example complicates things further by placing a smaller sized "preview" of the drawing on the cover sheet in the center (the box labeled printPreview).

All told, you have three interfaces in to draw circles: on the main interface and on each of the two print interfaces. The question is: how to do this in the most efficient and maintainable fashion? Start by creating a place to store information about the shapes a user has drawn. To do that, create a class called Circle with three properties: x-position (x), y-position (y), and color (c):

class Circle { var x:Number; var y:Number; var c:Number; // constructor function Circle(x:Number, y:Number, c:Number) { this.x = x; this.y = y; this.c = c; } function getX():Number { return this.x; } // etc.

The full source code contains a "getter" method for each of the three properties that follows the example of the getX() method above. ActionScript 2.0's class definitions are held outside the main application, so the main Flash file imports the Circle class creates an array in which to store circles:

import Circle; var circles = Array();

Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



Thanks for your registration, follow us on our social networks to keep up-to-date