Using the Print Action


Instead of using the limited Print command, you can use a more controllable printing option: the Print action. With it, you can specify not only which timeline you want to print, but also the print area. You even can use color effects, including transparency, when you print your Flash content.

Exercise 24.3 Adding the Print Action

Now it's time to add your first Print action! It's pretty painless, but watch out for all the options you have available.

  1. Open print_action.fla from the Chapter_24/Assets folder and save it to your hard drive. This file has one frame in each of the six layers (see Figure 24.4):

    Figure 24.4. The file has six layers: Actions/Labels, Printable Content, Overlay, Button, Input Text, and Background.

    graphics/24fig04.gif

    • Actions/Labels, Printable Content, Overlay, and Button. These layers are currently empty because you will be adding content to each.

    • Input Text. This layer contains an input text box with a variable name of text. You can select this text box and look at its properties in the Text Options panel (Window > Panels > Text Options).

    • Background. This layer contains the background for your movie (the Background Graphic movie clip). It is locked so that you don't accidentally alter it.

  2. Select frame 1 of the Overlay layer and drag an instance of the Overlay movie clip from the Library onto the Stage. Use the Info panel to position this instance at X: 0 and Y: 0. Lock the Overlay layer so that you don't change it accidentally in the next step.

  3. Select frame 1 of the Button layer and drag an instance of the Print Button symbol from the Library onto the Stage. Use the Info panel (Window > Panels > Info) to position this button at X: 135 and Y: 305.

  4. With the instance of the Print button selected, open the Actions panel. Make sure the Actions panel is set to Normal mode. Double-click the Print action in the Actions category in the Toolbox list. Leave all the default settings for the Print action for now. The following ActionScript should appear in the Actions list for this button:

     on (release) {     printNum (0, "bmovie");  } 
  5. Save your movie and choose Control > Test Movie. After the SWF opens in Test Movie mode, click the Print button. Your computer's Print dialog box opens. Accept the defaults and print the movie. (See Figure 24.5.) If at all possible, print the movie on a color printer.

    Figure 24.5. After the computer's Print dialog box opens, accept the defaults and print the movie.

    graphics/24fig05.gif

Grab the printed movie off the printer and take a look at it. You should notice that the movie scaled to the size of the paper on which you printed it. However, everything is hidden by a boring green rectangle! (The rectangle is gray if you printed on a black-and-white printer.) That's the Overlay movie clip. Even though it's semi-transparent in the editing environment, the default print settings make it appear otherwise . You learn how to fix this problem in the next section of this chapter.

Print as Vector versus Print as Bitmap

You can print your printable frames as vectors or a bitmap. When you print the content as vectors, the image is printed at a higher resolution, which provides the nice, smooth edges that you've come to expect from a Flash movie. However, any color effects, including the application of transparency, are ignored when the content is printed. If you choose to print your movie as a bitmap, those color effects are printed at the highest available resolution of the printer. The content might become pixelated, as bitmaps are prone to do.

Every time you add a Print action, you have to decide if you want to print the movie as vectors or as a bitmap. You have to consider the following when you make this decision:

  • Color effects. If you want your color effects (transparency, tint, brightness, and so on) to appear in the printed movie, you have to print as a bitmap.

  • Print quality. Printing the movie as vectors usually results in a higher quality printout. Although the highest available resolution of the printer is used when printing as a bitmap, this usually results in a lower quality printout. If print quality is important, use vectors.

  • Scalability. If you want your movie to scale to fit a certain size, you should print as vectors. Otherwise, you end up with pixelation in your printout because the bitmaps do not scale as smoothly as they would otherwise.

When you add the Print action, it is set to print your content as vectors by default. That's why you ended up with a nice, crisp rectangle instead of what you actually saw in the editing environment when you printed the movie in the last exercise! If you want that rectangle to print so that it's semi-transparent, you have to print the movie as a bitmap. If you do this, you might end up with a lower-resolution printout.

Exercise 24.4 Printing as a Bitmap

After you've made the leap to printing with ActionScript, you have to decide whether to print as vectors or as a bitmap. This exercise shows you how to tell your movie which one to use.

  1. Make sure you still have print_action.fla open from the last exercise. Select the instance of the Print Button symbol on the Stage and open the Actions panel.

  2. In the Actions panel, select the line that contains the Print action (it actually reads printNum, but more on that a little later). In the Parameters pane of the Actions panel, change the Print setting to As Bitmap. This changes the ActionScript in the Actions list to the following:

     on (release) {     printAsBitmapNum (0, "bmovie");  } 
  3. Save the movie and choose Control > Test Movie. After the Test Movie window opens, type some text in the space provided and click the Print button to once again print the movie. (See Figure 24.6.)

    Figure 24.6. The overlay appears transparent when you print the movie as a bitmap.

    graphics/24fig06.gif

When you collect the results from the printer, you should notice that with one simple flick of the Print setting, your printed movie now has a semi-transparent overlay, instead of a big, ugly rectangle. Depending on the resolution of your printer, you might also notice that the printed content now has some pixelated edges.

Specifying a Timeline to Print

When you use the Print action, you must specify a timeline to print. The timeline can be a level that has been loaded into the Flash Player (or Standalone Player), or it can be a movie clip that is on the Stage or work area of your main timeline. The timeline that you want to print must be fully loaded before you start printing.

By default, the Print action specifies the Level 0 timeline for printing. When a level is specified for printing, the Print action appears with the suffix "-Num" in the Actions list. This lets Flash know that it should be printing a level, not a movie clip.

Exercise 24.5 Printing a Movie Clip

You're becoming a printing pro! Now that you've got printing the main timeline down, it's time to try your hand at printing a movie clip's timeline.

  1. You should still have print_action.fla open from the last exercise. Unlock the Background layer. Select the instance of the Background Graphic movie clip in the Background layer and use the Instance panel to name it myClip. (See Figure 24.7.)

    Figure 24.7. Set the Instance Name to myClip.

    graphics/24fig07.gif

  2. Select the instance of the Print button on the Stage, and in the Actions panel, select the line containing your Print action. Change the Location to Target, and type myClip in the text box. Leave all other settings alone. (See Figure 24.8.)

    Figure 24.8. Change the Location to Target and type myClip in the text box.

    graphics/24fig08.gif

  3. Save the movie and choose Control > Test Movie. Type some text in the space provided and click the Print button to print the movie clip that you specified in the Print action.

    When you look at your printed content, notice that it looks a lot like everything else you printed, except that it no longer has that green rectangle over it. In addition, the text you typed and the Print button are missing! (See Figure 24.9.) They are missing because you printed only the timeline inside the myClip instance of the Background Graphic movie clip. That movie clip contains only graphicsit doesn't contain the overlay, the button, or the text that you typed.

    Figure 24.9. The contents of the movie clip are printed.

    graphics/24fig09.gif

  4. Return to the editing environment and open the Background Graphic movie clip in Symbol-Editing mode. Add a second frame to the Background Graphic movie clip.

  5. Save and test the movie again. When you print it, you should get two pages worth of printouts. You get two pages because, by default, the Print action prints every frame of the targeted timeline, and you currently have two frames in the targeted movie clip's timeline. You'll learn how to change the default later in this chapter.

Note

Before you try to print something, you first must make sure that it's fully loaded. This goes for both movie clips and movies loaded on levels. If something isn't loaded, it cannot be targeted by the Print action. You can use the _framesloaded property or the If Frame Is Loaded action to check to see that the printable content has loaded.


Although the movie clip that you target for printing must be on the Stage to print its contents, the movie clip does not have to be visible. If you apply any color effects to the movie clip, such as transparency, you still can print it out as if the color effects were not applied, if you just print the content as vectors. This is one way to hide the printable content while still having it on the Stage.

Another way to hide the printable content, and still be able to print it as a bitmap, is to set the content's _visible property to False. This does not affect its visibility in the printed output, but you won't be able to see it on the Stage. If you set the _visible property of any movie clip inside the printed movie clip to False, the movie clip is not visible in the printed output.

This technique would be useful for printing a coupon from a Flash movie. You might not want the coupon to appear on the Stage, which would enable users to print the coupon at the press of a button. You might also want to change the coupon based on certain variables in the movie, such as demographic information entered by the user . You can modify the _visible properties of several movie clips within the coupon to modify its appearance based on those variables.

Exercise 24.6 Hiding the Printable Content

You must have all printable content on the Stage, but what if you don't want the printable content to actually show up in the movie? This exercise shows you how to hide that content and still keep it on the Stage.

  1. In print_action.fla, select frame 1 of the Printable Content layer. Drag an instance of the Print Clip from the Library onto the Stage.

  2. Use the Info panel to position the instance of the Print Clip on the Stage at X: 0 and Y: 0. In the Instance panel, set this instance of the movie clip's name to printClip.

  3. Select frame 1 of the Actions/Labels layer and add the following ActionScript:

     printClip._visible = false; 
  4. Modify the Print action attached to the Print button so that it prints the printClip movie clip instead of the myClip movie clip. (See Figure 24.10.) Then, change the Print setting to As Vectors.

    Figure 24.10. Change the target of the Print action to printClip.

    graphics/24fig10.gif

  5. Add the following ActionScript to the button, in the line before the Print action:

     printClip.printText = text; 
  6. Save the movie and choose Control > Test Movie. You should see that the Print Clip movie clip is not visible on the Stagethat's because its _visible property is set to False. Type some text into the text box and click the Print button.

Take a look at the printed content. (See Figure 24.11.) It should be nicely scaled, and it should contain the text that you typed into the text box. The printed movie clip looks similar to the movie clip that you printed earlier in this chapter, but it does not contain a box around the text.

Figure 24.11. The printed movie clip.

graphics/24fig11.gif

Specifying Frames to Print

You can designate specific frames in a timeline as printable by labeling those frames #p. This can be useful if you have a large number of frames that should not be printed and a few that should. You just have to label the frames that you want to print with the label #p, and Flash prints just those frames and skips the rest. If you don't label any frames in the timeline #p, Flash prints every frame in the timeline targeted by the Print action.

Specifying specific frames to print could be very useful for your users. Your movie might be 20 frames long, but only two frames contain information that would be relevant to your visitors . Don't make them print out all that extra paper that will just end up in the recycling bin (or even worse , the trash).

Exercise 24.7 Specifying Frames for Printing

If you don't want to print every single frame in the targeted timeline, you have to specify which ones you do want to print. This exercise shows you how to do that.

  1. Make sure you still have print_action.fla open. Open the Print Clip movie clip in Symbol-Editing mode. This movie clip contains three layers:

    • Actions. Contains all the ActionScript for the movie clip.

    • Print Labels. Is empty right now, but you'll add something to it in just a bit.

    • Print Content. Contains a text box and some graphics. It's what you see when you print the movie.

  2. Add a frame (F5) to each layer. Select frame 2 of the Print Content layer and insert a keyframe.

  3. Select the keyframe that you added to the Print Content layer and drag an instance of the Overlay movie clip onto the Stage. Use the Info panel to position this movie clip at X: 0 and Y: 0. (See Figure 24.12.)

    Figure 24.12. Place an instance of the Overlay symbol in frame 2 of the Print Content layer.

    graphics/24fig12.gif

  4. Save and test the movie. Type some text in the space provided, and click the Print button.

    Take a look at what you printed out. You should have two pages. One page shows the content that you printed in the last exercise, and the other shows a big green (or gray) rectangle. (See Figure 24.13.)

    Figure 24.13. The printout has two pages.

    graphics/24fig13.gif

  5. Return to Symbol-Editing mode for Print Clip. Select frame 1 of the Print Labels layer and use the Frame panel to set the Label to #p.

  6. Save and test the movie again.

This time, your printout should be just one page. The #p label specified the frame that you wanted to print.

Specifying a Print Area

You've got down just about everything that there is to know about printing in Flash! There's just one more thing you need to knowhow to specify the print area for your printed content. The Bounding Box option of the Print action specifies the print area, and it affects how the printed content is displayed. You have the following choices for a bounding box:

  • Movie. Uses the dimensions of the movie as the print area. You can force this option to use the dimensions of a specific frame in the targeted movie, labeled #b, to specify the bounding box. This option is great for printing out a full-page document, as you will see in Exercise 24.8.

  • Max. Uses the Composite bounding box of all printable frames in the targeted timeline as the bounding box for the printed content. That means that if you have only one frame labeled #p in the targeted timeline, the bounding box of that frame is the bounding box for the printed content. If you have two frames labeled #p, the composite bounding box of both frames become the bounding box for the printed content.

  • Frame. Prints the content of each frame, using the bounding box of each individual frame. That means that the print area for each frame can change, and the objects in each frame are scaled to fit the full printed page.

You can use the bounding box to define a print area that's right for your needs. For example, you might want to print a full page of information when a user clicks the image of a product. Although your movie might be 550400, you can specify a print area that would be formatted correctly for a letter- sized piece of paper.

Exercise 24.8 Creating a Print Area

This exercise shows you a little trick that you can use to make the layout of your printable content easy to do.

  1. Open the Print Clip symbol in print_actions.fla in Symbol-Editing mode. Select frame 2 of the Print Labels layer and insert a keyframe. Label this keyframe #b.

  2. Select frame 2 of the Print Content layer and use the Rectangle tool to draw a rectangle. (See Figure 24.14.) Select the rectangle and use the Info panel to set the following:

    Width: 576

    Height: 756

    X:

    Y:

    Figure 24.14. Create a rectangle in the frame labeled #b. The rectangle is approximately the size of a letter-sized piece of paper.

    graphics/24fig14.gif

    Note

    Letter-sized paper is approximately 576x756 pixels. So, if you want to use a layout that looks good when printed on that size of paper, create a bounding box of that size and position your content inside it.

  3. Select the contents of frame 1 of the Print Content layer. Use the Info panel to position the contents of this frame at X: 70 and Y: 70.

  4. Save and test the movie. Type some text in the space provided, and then print the movie clip.

Take a look at the resulting printout. (See Figure 24.15.) The contents of the frame labeled #p (which is what you want printed) should be near the top-left corner of the page. Notice that it appears approximately one inch from the top and left sides of the edge of the paper.

Figure 24.15. The printed movie clip should appear nicely formatted on the page.

graphics/24fig15.gif



Inside Flash
Inside Flash MX (2nd Edition) (Inside (New Riders))
ISBN: 0735712549
EAN: 2147483647
Year: 2005
Pages: 257
Authors: Jody Keating

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net