What is Software? | What is Education? | What is Technology? | What is Research? | What is Wi-Fi? | What is Communication? | What is Customer Service?

Free SEO Tutorials & Help

Tutorials:   Adobe Flash   Adobe Photoshop   CorelDRAW   SEO  

Site Map

Website Development | Cable & Broadband Magazine | Solutions for Higher Education | Auction Anything Online

Adobe Flash Help & Tutorials

 Back to Topics

 

Process of Printing from SWF Files in Flash

Printing from SWF Files

Controlling printing

Supported printers

Using the ActionScript PrintJob class

Building a print job

Starting a print job

Adding pages to a print job

Specifying a target

Specifying a print area

Specifying printing as a vector image or bitmap graphic

Specifying a frame to print

Sending the print job to the printer

Deleting the print job

Printing frames independent of the PrintJob class

Designating printable frames (when not using the PrintJob object)

Specifying a print area (when not using the PrintJob object)

Using the print() function (when not using the PrintJob object)

Changing the printed background color

Using frame labels to disable printing

Printing from the Flash Player context menu

Printing from SWF Files

TOP

You can add printing functionality to your Macromedia Flash Basic 8 and Macromedia Flash Professional 8 document that lets users print from Flash Player. You can use the ActionScript PrintJob class, or you can use the print() or printAsBitmap() ActionScript functions. Users can also access the Flash Player context menu and select the Print command there.


Additionally, users can print from a browser, rather than from Flash Player, by selecting a command such as File > Print from the browser window. However, printing from Flash Player directly, rather than from a browser window Print menu, offers several advantages, including the following:

  • Users can print all frames or certain frames that you've labeled as printable from Flash Player. Additionally, you can set the print area of a frame.

  • You can specify that content print as vector graphics (to take advantage of higher resolution) or as bitmaps (to preserve transparency and color effects).

  • The ActionScript PrintJob object improves upon the print() and printAsBitmap() functions by adding the ability to print dynamically rendered pages as a single print job. The PrintJob object also provides the user's printer settings, which can be used to format reports specifically for the user.

  • Flash Player versions earlier than 4.0.25 (Windows) or 4.0.20 (Macintosh) do not support printing frames directly. Flash Player 7 and later supports the PrintJob class.
     

Controlling printing

TOP

To control what users can print, remember the following items as you set up documents and movie clips for printing:

  • Adjust the page layout in any frames that you designate as printable to match the desired printed output. Using Flash Player, you can print all shapes, symbols, bitmaps, text blocks, and text fields. Levels in a SWF file are not composited on print output.

  • The Flash Player printer driver uses the HTML settings for dimension, scale, and alignment in the Publish Settings dialog box. Use these settings to control the print layout.

  • The selected frames print as they appear in the movie clip symbol. You can let users print a movie clip that is not visible in a browser by setting the movie clip's _visible property to false using the Actions panel. Changing the property of a movie clip with the setProperty action, tweening, or any transformation tool does not affect how a movie clip prints.

  • For a movie clip to be printable, it must be on the Stage or workspace and it must be given an instance name.

  • All elements must be fully loaded to print. You can use the movie clip _framesloaded property to check whether the printable content is loaded. For more information,e.

Supported printers

TOP

With Flash Player, you can print to PostScript and non-PostScript printers. For a list of supported Flash Player printing platforms,

 

Using the ActionScript PrintJob class

TOP

TThe ActionScript PrintJob class, in addition to offering improvements to print functionality available with the print() method, lets you also render dynamic content at runtime, prompt users with a single print dialog box, and print an unscaled document with proportions that map to the proportions of the content. This capability is especially useful for rendering and printing external dynamic content, such as database content and dynamic text.

Additionally, with properties populated by the PrintJob.start()method, your document can access your user's printer settings, such as page height, width, and orientation, and you can configure your document to dynamically format Flash content that is appropriate for the printer settings.

Building a print job

TOP

To build a print job, you use functions that complete the tasks in the order outlined in this section. The sections that follow the procedure provide explanations of the functions and properties associated with the PrintJob object.

Because you are spooling a print job to the user's operating system between your calls to PrintJob.start() and PrintJob.send(), and because the PrintJob functions might temporarily affect the Flash Player internal view of onscreen Flash content, you should implement print-specific activities only between your calls to PrintJob.start() and PrintJob.send(). For example, the Flash content should not interact with the user between PrintJob.start() and PrintJob.send(). Instead, you should expeditiously complete formatting of your print job, add pages to the print job, and send the print job to the printer.


To build a print job:

  1. Create an instance of the print job object: new PrintJob().

  2. Start the print job and display the print dialog box for the operating system: PrintJob.start().

  3. Add pages to the print job (call once per page to add to the print job): PrintJob.addPage().

  4. Send the print job to the printer: PrintJob.send(). For more information,

  5. Delete the print job: delete PrintJob. For more information,

The following example shows ActionScript that creates a print job for a button:

myButton.onRelease = function()

{
var my_pj = new PrintJob();
var myResult = my_pj.start();
if(myResult){
myResult = my_pj.addPage (0, {xMin : 0, xMax: 400, yMin: 0,
yMax: 400});
myResult = my_pj.addPage ("myMovieClip", {xMin : 0, xMax: 400,
yMin: 400, yMax: 800},{printAsBitmap:true}, 1);
myResult = my_pj.addPage (1, null,{printAsBitmap:false}, 2);
myResult = my_pj.addPage (0);

my_pj.send();
}
delete my_pj;
}

Only one print job can run at any given time. A second print job cannot be created until one of the following events has happened with the previous print job:

  • The print job was entirely successful and PrintJob.send() method was called.

  • The PrintJob.start() method returned a value of false.

  • The PrintJob.addPage() method returned a value of false.

  • The delete PrintJob method has been call

Starting a print job

TOP

Calling the PrintJob.start() method prompts Flash Player to spool the print job to the user's operating system and also prompts the user's operating system print dialog box to appear.


If the user selects an option in the print dialog box to begin printing, the PrintJob.start() method returns a value of true. (The value is false if the user cancels the print job, in which case the script should call only delete). If successful, the PrintJob.start() method sets values for the paperHeight, paperWidth, pageHeight, pageWidth, and orientation properties.


Depending on the user's operating system, an additional dialog box might appear until spooling is complete and the function PrintJob.send is called: Calls to PrintJob.addPage() and PrintJob.send() should be made expeditiously. If ten seconds elapse between the PrintJob.start() function call and the PrintJob.send() function call, which sends the print job to the printer, Flash Player effectively calls PrintJob.send(), causing any pages that are added using PrintJob.addPage() to be printed and spooling to stop.


When a new print job is constructed, the PrintJob() properties are initialized to 0. When PrintJob.start() is called, after the user selects the print option in the operating system print dialog box, Flash Player retrieves the print settings from the operating system. The PrintJob.start() function populates the following properties:

Property

Type

Unit

Notes

PrintJob.paperHeight

number

points

Overall paper height.

PrintJob.paperWidth

number

points

Overall paper width

PrintJob.pageHeight

number

points

Height of actual printable area on the page; does not include any user-set margins

PrintJob.pageWidth

number

points

Width of actual printable area on the page; does not include any user-set margins

PrintJob.orientation

string

n/a

Portrait or landscape orientation

NOTE : A point is a print unit of measurement that is equal in size to one pixel, a screen unit of measure. For more information about unit equivalencies, see About scaling.

 

Adding pages to a print job

TOP

You add pages to your print job with the PrintJob.addPage() method. Although the method can include as many as four parameters, the only required parameter is target/level. The three optional parameters are printArea, options, and frameNum.

If you are not using a particular optional parameter but are using other optional parameters, use NULL in place of the excluded optional parameter.
With all four parameters, the function uses the following syntax:

MyPrintJob.addPage(target[,printArea:Object, options:Object, frameNum:Number]):boolean;

If you provide an invalid parameter, the print job uses default parameter values, which are specified in the following sections.

Each call to add a new page is unique, which lets you modify parameters without affecting previously set parameters. For example, you can specify that one page print as a bitmap image and another page print as a vector graphic.

You can add as many new pages to your print job as the print job requires. One call to add a page equals one printed page.

NOTE Any ActionScript that needs to be called to change a resulting printout must run before the PrintJob.addPage() method is called. The ActionScript can, however, run before or after a new PrintJob(). If a frame has a call to the PrintJob.addPage() method, the call itself does not guarantee that the ActionScript script on that frame will run when that frame is printed.

 

Specifying a target

TOP

FThe target parameter can be either a number that represents a level (such as 0 for the _root document), or a string that represents the instance name of a movie clip ("myMovieClip").


 

Specifying a print area

TOP

IThe printArea optional parameter includes the following values:


{xMin:Number, xMax:Number, yMin:Number, yMax:Number}


The xMin, xMax, yMin, and yMax values represent screen pixels relative to the target level or movie clip registration point. The print area orientation is from the upper left corner of the printable area on the page. If the print area is larger than the printable area on the page, then the print data that exceeds the right and bottom edge of the page is clipped.

 

If you don't specify a print area, or if you specify an invalid print area, the print area defaults to the Stage area of the root document.

About scaling

A print job using the PrintJob class prints Flash content, by default, without scaling it. For example, an object that is 144 pixels wide on screen will print as 144 points, or 2 inches wide (One point equals one pixel. In the authoring tool, 72 pixels equals one inch; on paper, 72 points equals one inch.)


To understand how Flash screen content maps to the printed page, it helps to understand screen and print units of measure. Pixels are a screen measurement and points are a print measurement. Both pixels and points equal 1/72 of an inch. A twip is 1/20 of a point and pixel.


The following list further illustrates the relationship between units of measure.

  • 1 pixel = 20 twips

  • 1 point = 20 twips

  • 72 pixels = 1 inch

  • 72 points = 1 inch

  • 567 twips = 1 cm

  • 1440 twips = 1 inch

To scale a movie clip before printing, set its MovieClip.xscale and MovieClip.yscale properties before calling this method, and set them back to their original values afterward. If you scale a movie clip and also pass a value for the printArea property, the pixel values passed to printArea reflect the original size of the movie clip. That is, if you set a movie clip's scale to 50% and specify a print area of 500 x 500 pixels, the content that prints is identical to the content that would print if you didn't scale the movie clip; however, it prints at half the size
 

Specifying printing as a vector image or bitmap graphic

TOP

lThe options parameter lets you specify whether to print as a vector graphic or bitmap image. When using this optional parameter, use the following syntax:

{printAsBitmap:boolean}

The default value is false, which represents a request for vector printing. Remember the following suggestions when determining which value to use:

  • If the content that you're printing includes a bitmap image, you should specify that the print job print as a bitmap to include any transparency and color effects.

  • Conversely, if the content does not include bitmap images, you should specify that the print job print as vector graphics to take advantage of the higher image quality.

     

Specifying a frame to print

TOP

The frameNum parameter lets you specify a frame to print. If you do not specify a frame number parameter, the current frame of the target or level specified as the first parameter when adding a page prints by default.

 

Sending the print job to the printer

TOP

To send the print job to the printer after using the addPage() calls, use the PrintJob.send() method, which causes Flash Player to stop spooling the print job so that the printer starts printing.

 

Deleting the print job

TOP

YAfter sending the print job to a printer, use the ActionScript function delete PrintJob() to delete the PrintJob object, which frees memory.

 

Printing frames independent of the PrintJob class

TOP

AfThe PrintJob class, available for Flash Player 7 and later, offers many advantages over the print() and printAsBitmap() methods for printing. However, to print targeting Flash Player 6 and earlier versions, back to Flash Player 4.0.25 (Windows) and 4.0.20 (Macintosh), you can use print() and printAsBitmap() functions and frame labels--classic functionality that remains part of the authoring tool and does not use the PrintJob class.

To set up printing from Flash Player independent of the PrintJob class, you can specify frames to print and set their print area.
 

Designating printable frames (when not using the PrintJob object)

TOP

TAll frames in the specified Timeline print by default. You might want to limit the number of frames that print--for example, if you have a lengthy animation of dozens of frames. You can designate specific frames in a SWF file as printable in order to print only those frames; unspecified frames won't print.

To specify frames as printable, you label the frames.

To designate printable frames:

  1. Open or make active the SWF file that you want to publish.

  2. Select the desired frame in the Timeline that you want to make printable and add a keyframe.

  3. In the Property inspector (Window > Properties), enter #p in the Label text box to specify the frame as printable.

  4. Repeat steps 2 and 3 for each frame you want to designate as printable.

NOTE If you have multiple #p labels in your document, you might receive an Output window message when you test or publish your SWF file that indicates that the document contains duplicate frame labels. You can ignore the message if the duplicate labels are all #p labels.

To control what users can print, remember the following items as you set up documents and movie clips for printing:

  • Adjust the page layout in any frames that you designate as printable to match the desired printed output. Using Flash Player, you can print all shapes, symbols, bitmaps, text blocks, and text fields. Levels in a SWF file are not composited on print output.

  • The Flash Player printer driver uses the HTML settings for dimension, scale, and alignment in the Publish Settings dialog box. Use these settings to control the print layout.

  • The selected frames print as they appear in the movie clip symbol. You can let users print a movie clip that is not visible in a browser by setting the movie clip's _visible property to false using the Actions panel. Changing the property of a movie clip with the Set Property action, tweening, or any transformation tool does not affect how a movie clip prints.

  • For a movie clip to be printable, it must be on the Stage or workspace and it must be given an instance name.

  • All elements must be fully loaded to print. You can use the movie clip _framesloaded property to check whether the printable content is loadedd.

Specifying a print area (when not using the PrintJob object)

TOP

By default, when frames are printed, the document file's Stage determines the print area. Any object that extends off the Stage is clipped and does not print. Loaded movies use their own Stage size for the print area, not the main movie's Stage size.

As an alternative to using a document's Stage size, you can set the following print areas:

  • For either the Flash Player context menu or the print() function, you can designate the SWF content bounding box as the print area for all frames by selecting an object in one frame as the bounding box. This option is useful, for example, if you want to print a full-page data sheet from a web banner.

  • With the print() function, you can use the composite bounding box of all printable frames in a Timeline as the print area--for example, to print multiple frames that share a registration point. To use the composite bounding box, you use the bMax parameter, as shown in the following example:

    print ("myMovie", "bmax")

  • With the print() function, you can change the print area for each frame, scaling objects to fit the print area--for example, to have objects of different sizes in each frame fill the printed page. To change the bounding box per frame, use the Frame parameter in the Print action parameters, as shown in the following example:

    print ("myMovie", "bframe")

  • With the print() function, you can designate the bounding box of a specific frame in a document as the print area for all printable frames in the document, as shown in the following example:

    print ("myMovie", "bmovie")

    You use the label #b to designate a frame to be used to designate the print area. The label #b must be on the same layer as a frame labeled #p.

To specify a print area when printing frames:

  1. Open the Flash document (FLA file) containing the frames you will set to print.

  2. Select a frame that you have not specified to print with a #p frame label. Select a frame that is on the same layer as one labeled #p.

    To organize your work, you can select the next frame after one labeled #p.

  3. Create a shape on the Stage the size of the desired print area.

    You can also select a frame with any object of the appropriate print area size to use that frame's bounding box.

  4. Select the frame in the Timeline that contains the shape you want to use for the bounding box.

  5. If the Property inspector does not appear, select Window > Properties.

  6. In the Property inspector, enter #b for Label to specify the selected shape as the bounding box for the print area.

You can enter only one #b label per Timeline. This option is the same as selecting the Movie bounding box option with the Print action.

 

Using the print() function (when not using the PrintJob object)

TOP

The basic syntax for the print() function, which you can associate with a button or other trigger in your document to activate printing, is shown as follows:

print (target, "Bounding box");


The target parameter specifies the location of the frames that print, and the bounding box parameter specifies the print area.

You can add a print() function to a button or other element in your document to let users print Flash content. You assign the print() function to a button, frame, or movie clip. If you assign a print() function to a frame, the action executes when the playhead reaches the designated frame.

The print() function lets you print frames in other movie clips in addition to the main Timeline. Each print() function sets only one Timeline for printing, but the action lets you specify any number of frames within the Timeline to print. If you attach more than one print() function to a single button or frame, the Print dialog box appears for each action executed.
 

Changing the printed background color

TOP

With Flash Player, you can print the background color set in the Document Properties dialog box. You can change the background color for only the frames to be printed by placing a colored object on the lowest layer of the Timeline being printed.


To change the printed background color:

  1. Place a filled shape that covers the Stage on the lowest layer of the Timeline that will print.

  2. Select the shape and select Modify > Document. Select a color for the printing background.

    This changes the entire document's background color, including that of movie clips and loaded movies.

  3. Do one of the following:

    • To print that color as the document's background, make sure that the frame in which you placed the shape is designated to print.

    • To maintain a different background color for nonprinting frames, repeat steps 2 and 3. Then place the shape on the lowest layer of the Timeline, in all the frames that are not designated to print.

 

Using frame labels to disable printing

TOP

IIf you don't want any of the frames in the main Timeline to print, you can label a frame as !#p to make the entire SWF file nonprintable. Labeling a frame as !#p dims the Print command in the Flash Player context menu. You can also remove the Flash Player context menu.

If you disable printing from Flash Player, the user can still print frames using the browser Print command. Because this command is a browser feature, you cannot control or disable it using Flash.

To disable printing in the Flash Player context menu by dimming the Print command:

  1. Open or make active the Flash document (FLA file) that you want to publish.
  2. Select the first keyframe in the main Timeline.
  3. Select Window > Properties to view the Property inspector.
  4. In the Property inspector, for Label enter !#p to specify the frame as nonprinting.

You need to specify only one !#p label to dim the Print command in the context menu.
NOTE You can also select a blank frame (rather than a keyframe) and label it #p.

To disable printing by removing the Flash Player context menu:

  1. Open or make active the Flash document (FLA file) that you want to publish.
  2. Select File > Publish Settings.
  3. Select the HTML tab and deselect Display Menu.
  4. Click OK.
     
Printing from the Flash Player context menu

TOP

You can use the Print command in the Flash Player context menu to print frames from any Flash SWF file.


The context menu's Print command cannot print transparency or color effects and cannot print frames from other movie clips; for more sophisticated printing capabilities, use the PrintJob object or the print() function.


To print frames using the Flash Player context menu Print command:

  1. Open the document with frames you want to print.

    The command prints the frames labeled #p using the Stage for the print area or the specified bounding box.

    If you haven't designated specific frames to print, all frames in the document main Timeline print.

  2. Select File > Publish Preview > Default or press F12 to view your Flash content in a browser.

  3. Right-click (Windows) or Control-click (Macintosh) in the Flash content in the browser window to display the Flash Player context menu.

  4. Select Print from the Flash Player context menu to display the Print dialog box.

  5. In Windows, select the print range to select which frames to print:

    • Select All to print all frames if no frames are labeled.

    • Select Pages and enter a range to print the labeled frames in that range.

    • Select Selection to print the current frame.

  6. On the Macintosh, in the Print dialog box, select the pages to print:

    • Select All to print the current frame if no frames are labeled or to print all labeled frames.

    • Select From and enter a range to print the labeled frames in that range.

  7. Select other print options, according to your printer's properties.

  8. Click OK (Windows) or Print (Macintosh).

    NOTE Printing from the context menu does not interact with calls to the PrintJob object.
     

Copyright ADOBE - All Rights Reserved Worldwide

 

 

More Topics:

Working with Flash Documents

How to work in Flash WorkSpace

Working with Projects in Flash

Process to Build your First Application in Flash

Using Symbols, Instances and Library Assets in Flash

How to Build Video Player in Flash

How to Work with Color, Strokes and Fills in Flash

How to Create Document in Flash

What is Vector and Bitmap Graphics in Flash

How to Create a Banner in Flash, Part 1

How to Work with Text in Flash

How to Create a Banner in Flash, Part 2

How to Use Imported Artwork in Flash

How to Create a Banner in Flash, Part 3

How to Work with Graphic Objects in Flash

How to Work with Layers in Flash

How to Use Filters and Blends

Working with Graphics in Flash

What is Accessibility Features in Flash

How to Create Motion (Shape Tween & Motion Tween) in Flash

How to Create an Application in Flash

What is Masking in Flash

How to Work with Video in Flash

How to Use Layout Tools in Flash

What are Behaviors in Flash

How to Work with Sound in Flash

How to Create Symbols and Instances in Flash

What is ActionScript in Flash

How to Write ActionScript With Script Assist in Flash

How to Add Button Animation and Navigation in Flash

What is Data Integration in Flash

How to Work with Screens

How to Create a Presentation with Screens

What is Extending Flash

How to Create Multilanguage Text in Flash

How to Create Graphics: Draw in Flash

What is Flash Lite

Ways of Data Integration

How to Create Graphics: Create a Timeline Animation in Flash

Getting Started with Flash Lite in Flash

How to Publish Flash Documents

How to Create Graphics: Making Animations with Easing

Learning Flash Lite 1.X ActionScript in Flash

How to Export Flash Content and Images from Flash

How to Create Graphics: Applying Gradients in Flash

Process of Writing and Editing ActionScript 2.0 in Flash

How to Create Accessible Content in Flash

How to Create Graphics: Apply Graphic Filters and Blends

What is Data and Data Types in Flash

Process of Printing from SWF Files in Flash

Using ActionScript: How to Use Script Assist mode in Flash

Learn Syntax and Language Fundamentals in Flash

How to Create E-learning Content in Flash

Using ActionScript: How to Write Scripts in Flash

Working with Functions and Methods in Flash

Process of Using Templates in Flash

Using ActionScript: Process of Adding Interactivity in Flash

What are Classes in Flash

Control Tag Summary of XML to UI in Flash

Using ActionScript: How to Create a Form with Conditional Logic and Send Data in Flash

What is Inheritance in Flash

What is Data Integration: Overview

Using ActionScript: How to Work with Objects and Classes in Flash

Overview on Interfaces in Flash

What is Data Integration: Using XML for a Timesheet

How to Work with Text and Strings in Flash

How to use Handling Events in Flash

What is Data Integration: Using XUpdate to Update the Timesheet

Learning Animation, Filters and Drawings in Flash

How to Work with Movie Clips in Flash

How to Create Interaction with ActionScript in Flash

How to Work with Images, Sound, and Video in Flash

How to Work with External Data in Flash

What is Security in Flash

How to Debug Applications in Flash

List of Error Messages in Flash

Using Object-Oriented Programming with ActionScript 1.0 in Flash

How to Write Scripts for Earlier Versions of Flash Player in Flash

List of all Keyboard Keys and Key Code Values for using in Flash

Terminology

Introduction to Components in Flash

What are Components in Flash

How to Create an Application with Components

How to Work with Components in Flash

How to Handle Component Events in Flash

How to Customize Components in Flash

How to Create Components in Flash

What is Collection Properties in Flash