in black and white
Main menu
Share a book About us Home
Biology Business Chemistry Computers Culture Economics Fiction Games Guide History Management Mathematical Medicine Mental Fitnes Physics Psychology Scince Sport Technics

macromedia flash mx - Reinhardt R.

Reinhardt R., Lott J macromedia flash mx - John Wiley & Sons, 2004. - 987 p.
ISBN 0-7645-4354-7
Download (direct link): macromediaflash2004.pdf
Previous << 1 .. 254 255 256 257 258 259 < 260 > 261 262 263 264 265 266 .. 419 >> Next

mcDialog Instance
The other primary element in this example is the mcDialog MovieClip object that appears on the stage via the attachMovie() method in the showDialog() method, which is invoked by the cbtPrint instance. Take a look inside the dialogClip symbol, located in the Library panel. Double-click the dialogClip symbol there, and examine the layers within its timeline. Four elements enable the functionality of this timeline: the tMessage Dynamic text field, the OK button (cbtOK i nstance), the Cancel button (cbtCancel i nstance), and the first frame of the actions layer.
Chapter 22 ¦ The PrintJob Class 557
The content of the tMessage Dynamic text field is scripted by the actions on frame 1. The most important aspect of this text field is that it is named tMessage in the <Instance Name> field of the Property inspector. Select the first frame of the actions layer and look at the last line of code in the Actions panel:
tMessage.text = "Do you want to print " + this.printTarget._totalframes + ^
" pages from this Flash movie?";
Here, you concatenate string values to be displayed in the tMessage field. The dynamic element of this message is the printTarget variable. Remember the showDialog() method: A printTarget property (or variable) is created on the mcDialog timeline. When the method is executed by the cbtPrint instance, this.printTarget._totalframes has a value of 2 because two frames in the mcChars instance are printed.
Take a look at the two components on the dialogClip timeline: the OK and Cancel Button component instances. Select the OK button and open the Property inspector. This cbtOK instance has a label value of OK. To see how this value is used, go back to frame 1 of the actions layer and open the Actions panel. The following code is used by both Button component instances:
this.printControl = function(oEvent:Object):Void { var sLabel:String;
var mcOwner:MovieClip =; var sLabel =; if(sLabel == "OK") mcOwner.printProceed();
cbtOK.addEventListener("click", this.printControl); cbtCancel.addEventListener("click", this.printControl);
When the user clicks the OK button, the code within the printControl() method executes. Whenever a component instance executes one of its listener’s event handlers (which is defined after the function), an event object is passed to the click handler. The oEvent argument, therefore, will represent this event object. If one of the component buttons executes the function, a local variable named sLabel will be set to the label value of the component button — either "OK" or "Cancel" i n the case of this example. If the sLabel variable equals "OK", the printProceed() method on the instance will be executed. Remember that the printProceed() method contains all of the PrintJob object actions, which send output to the printer. If the Cancel button is pressed, the printProceed() function is not processed. Regardless of which button is pressed, the dialog instance is removed from the stage (mcOwner.removeMovieClip();). After the printControl() method is defined, the method is set as an event listener for both the OK button (represented as cbtOK) and the Cancel button (represented as cbtCancel).
After the addEventListener() methods establish the printControl() method for the component buttons, a Key listener object is created to detect if the user presses the Enter key:
var oPrintKey:Object = {}; oPrintKey.onKeyDown = function():Void { if(Key.isDown(Key.ENTER)){
printControl({target: cbtOK});
558 Part V ¦ The Movie Classes
When an instance of the dialogClip symbol loads onto the stage, the oPrintKey listener object is initiated and added as a listener to the Key class. If the Enter key is pressed while an instance of dialogClip i s on the stage, the printControl() method executes with an oEvent object mimicking the cbtOK i nstance, enabling the same printProceed() method that the OK button does.
In summary, you can reuse these custom methods and the dialogClip symbol in your Flash movies to create a more user-friendly interface that lets users know how many pages are sent to the printer — before they accidentally print 10 pages of paper!
Working with Hidden Content
You can use the PrintJob API to output content not seen in the Flash movie by your Web visitors. By setting the _visible property of printable MovieClip objects to false, you can hide them on the movie’s stage, yet still print the frames within. For this example, you learn not only how to print hidden content but how to offer your visitors the choice of printing color or grayscale artwork. Keep in mind that the file contains a grayscale duplicate symbol of a colored Movie Clip symbol. If you’re wondering why a grayscale version is offered here, read the sidebar “Printing Issues with Flash: Color, Grayscale, and PostScript,” earlier in this chapter.
On the - Make a copy of the PrintJob_dialog_choice.fla and PrintJob_dialog_choice
Previous << 1 .. 254 255 256 257 258 259 < 260 > 261 262 263 264 265 266 .. 419 >> Next