Flash MX Printing
IN THIS CHAPTER
- Sample Questions
There are a variety of ways that an end user can print Flash content, and some are more effective than others. Following is a list of the primary ways in which a user can execute a Print command, and some notes about each one:
Browser File Menu. If a user doesn't see an immediately recognizable printer interface element directly in your Flash content, the Browser File menu is most likely the first place they will go to print. Unfortunately, this method is extremely difficult to control from a development perspective, and will subsequently have varying results. The most important notes about this method are that the user will be printing only (and exactly) what they see at the proportions of the browser window, and Flash developers currently have no way to consistently disable this functionality.
Flash Player Context Menu. This is the menu that appears on right-click (Windows) or ctrl + click (Macintosh). In the absence of a visible Print button, this is the second place that many users will go to print. By default, the context menu is enabled in the Flash Player, and consequently, if a developer has not invested any time in the printable configuration of his or her movie, executing a Print command with this method can prove disastrous. If there are no frames in the main Timeline that are designated as printable frames, the Flash Player will begin printing every single frame. Fortunately, changing a few export settings can disable the Flash Player context menu. Because this menu exists only for Flash content, and only when developers have not disabled it, many users are still unaware that this is even an option. It is not recommended that this feature be relied upon in cases where printing Flash content is desirable.
When a user chooses to print from this menu, she can only print frames designated in the main Timelines, and they will not be able to print transparencies or color effects.
If a user chooses to print from the context menu, and there are either no frames or two or more frames designated as printable, the "Page Range" area of his or her print dialogwhere they would normally determine "number of pages"will actually mean "specified frames".
Using the Print action. Direct printing from the Flash player using the print action has been available since the distribution of Flash Player revision 4.0.20 This is by far the most desirable way to enable printing. Making effective use of the built-in print action will give developers the most robust control over layout, content, and usability.
The remainder of this chapter will be devoted to the implementation details of the print action feature.
The Flash print action comes in two primary commands: Each of these commands has two variations. The primary actions are, Print as Vector (print) or Print as Bitmap (printAsBitmap). Within each of these commands are two variants. You can choose to either print the contents of a movie clip or a single Flash _level. All four versions of the print action will accept an argument that identifies the print area. If this argument is not given, the main movie stage dimensions are used. Some examples are as follows:
print(_root.myClip, "bmax"); printNum(_level0, "bmax"); printAsBitmap(_root.myClip, "bmax"); printAsBitmapNum(_level0, "bmax");
Any variant of the print action can (and usually should) target movie clips whose _visible property is set to 0. These movie clips will still print correctly, but they will not appear in the Flash Player-and subsequently can be formatted for the printed page rather than the browser dimensions.
The use of levels as a targeting mechanism should be avoided in nearly every case. By targeting movie clip instance names, your ActionScript will be more explicit and far easier to debug. The only exception to this rule is in cases when you're attempting to target an item within a known stacking order, and you have no need to identify which movie clip that item is an instance of.
Unfortunately, in many cases, printing features tend to be requested after a project has already launched or is nearly complete. It can be extremely time-consuming to implement such features during later phases if attention was not given to them during development. Every Flash application project should be designed and constructed with the idea that certain logical components will eventually become printable. This will cost very little time and energy up front, and will save considerable time and money down the road.
The following sections describe each variation on the print action in more detail.
Print will print high-quality, vector-based printouts of all frames of the target timeline or, if any have been identified, only those frames with a #p frame label. This is the best way to achieve extremely clean, high-resolution print output with an absolutely minimal amount of network traffic and CPU usage.
The print and printNum actions do not print alpha channels, bitmaps, or color effects.
PrintNum is the same as the print action, but will print the specified _level in the target movie clip.
PrintAsBitmap will print out a bitmap version of each frame in the target movie clip or only those frames which contain a #p label. This action will print at the highest resolution available on the end users' printer and as a result, can sometimes take an extraordinarily long time to execute. This action will print transparencies and color effects as well as bitmap images.
In many cases, the Print As Bitmap action provides inferior print quality and much longer print delays than the standard print action, and should only be used when absolutely necessary.
PrintAsBitmapNum is the same as printAsBitmap, but will print only the specified _level.
Bounding Box Arguments
The Bounding Box argument is an optional second argument available within all four variations of the print action. This argument will define the outermost limits of the printable area. If a movie clip is identified as the bounding box, the movie clip's dimensions will be superimposed over any printable frames, and any assets that fall outside of those "bounds" will not be printed. Each variation of the print action also allows for a bounding box argument. If this argument is left blank, the main movie stage dimensions will be used as the bounding box. If this is an undesirable aspect ratio for the printed page (as it will usually be), this argument can be one of the following string values:
"bmovie" will designate a specific frame in the movie as the bounding box identifier for the entire movie. To identify the frame, it must contain a frame label of #b.
If you are duplicating or attaching movie clips to a timeline, and you have a frame marked with the #b label, it is probable that your duplicated movie clips will also exist in the designated frame, subsequently changing the bounds of the printable area.
The following code will print frames in myClip_mc and use the #b frame label to identify the boundaries of all printable frames. The #b frame label must exist within the myClip_mc timeline. For example:
"bmax" will simply determine the largest bounding box out of the frames that have been identified as printable, and it will use the largest as the bounding box for all frames printed. If no frames contain the #p frame label, then this will apply to all frames in the movie clip.
The following example will print all frames in myClip_mc and use the largest frame to identify the bounds. This will retain proportional sizes from one frame to the next:
Using "bframe" will force each frame to use its own bounding box as the bounds for that particular page. If various frames contain various-sized groups of objects, each frame will fill the printed page.
The following example will print all frames in myClip_mc and will use the bounds of each frame for the printable page, thereby scaling assets and destroying any proportional relationships from one frame to the next: