Week 12: Odds and Ends
Today we are going to cover a few useful things that didn’t fit anywhere else:
- Dynamically setting masks
- Printing from the swf
- Setting the swf to display fullscreen
Dynamic Masks
Setting a mask with ActionScript is very simple. You can set any Display Object in the Display List as the mask property of any other Display Object:
maskeeObject.mask = maskerObject;
Printing
To print from a .swf, you use the PrintJob object. PrintJob is a class of the flash.printing package. First, you create a new PrintJob object:
var myPrintJob = new PrintJob();
Next, begin the print job using the start method:
myPrintJob.start();
Then add a new page to the print job using the addpage method. This takes a number of arguments, some required, some optional:
myPrintJob.addpage(sprite:Sprite, printArea:Rectangle = null, options:PrintJobOptions = null, frameNum:int = 0);
- sprite: The instance name of the Sprite object to print. (required)
- printArea: The print area is passed as the name of a Rectangle object which must be defined earlier in the code. If you omit this, the entire area of the sprite will be printed.
- options: You can use this to specify whether to print the page as a bitmap, as a Boolean value: {printAsBitmap:true}. If you do not specify this, the default is false. Printing as a bitmap will result in lower quality, but you must do this if your target has alpha values or color effects applied to it.
- frameNum: This specifies a frame of the sprite to print. If omitted, it prints the current frame.
Next, you send the print job to the printer using the send method:
myPrintJob.send();
There are a number of other properties you can set for a print job, such as orientation and page attributes, detailed here:
If you want your user to be able save a jpeg out of your swf rather that print, there is a tutorial here:
You’ll need to import some additional AS3 libraries to get this working.
Fullscreen Display
You can present a swf as a fullscreen application using the fscommand function of the flash.system package. fscommand takes two arguments: command and args.
Entering fullscreen mode:
fscommand("fullscreen","true");
Exit the fullscreen mode:
fscommand("fullscreen","true");
Prevents swf content from being scaled:
fscommand("allowscale","false");
Note: fscommand only working in the standalone Flash Player, or in a projector. It will not work in a Web browser or the test player in the Flash IDE.
Additional options for fscommand can be found here:
Homework
Final project presentations are in two weeks. Presentation of your project is mandatory. Each student will have 10 minutes to present and get comments.
Next week will be an in class work session. Your code should be at a point where you have identified issues that you can work through with me in class.