<!-- Print preview code --> <mx:Script> <![CDATA[ import mx.core.IUIComponent; import mx.graphics.ImageSnapshot; private function takeSnapshot(source:IBitmapDrawable):void { var imageSnap:ImageSnapshot = ImageSnapshot.captureImage(source); var imageByteArray:ByteArray = imageSnap.data as ByteArray; swfLoader.load(imageByteArray); printPanel.visible = true; printAppBar.visible = true; printBackground.visible = true; } ]]> </mx:Script> <!-- Print for real (from ESRI FLEX samples) --> <mx:Script> <![CDATA[ import mx.printing.FlexPrintJobScaleType; import mx.printing.FlexPrintJob; import mx.controls.Alert; private function doPrint(myFlexPrintJobScaleType:String):void { // Create an instance of the FlexPrintJob class. var myPrintJob:FlexPrintJob = new FlexPrintJob(); // Start the print job. if (myPrintJob.start()) { try { // hide the zoom slider so it won't be printed myMap.zoomSliderVisible = false; // Add the panel to print. myPrintJob.addObject(printPanel, myFlexPrintJobScaleType); // turn the zoom slider back on myMap.zoomSliderVisible = true; } catch (error:Error) { Alert.show(error.toString()); } // Send the job to the printer. myPrintJob.send(); } } ]]> </mx:Script> <!-- Closing the print window --> <mx:Script> <![CDATA[ import mx.controls.Alert; private function closePrintWindow():void { printBackground.visible = false; printAppBar.visible = false; printPanel.visible = false; } ]]> </mx:Script> <!-- MXML for the Print Preview Panel --> <mx:Canvas height="100%" width="100%" alpha="0.5" id="printBackground" visible="false" backgroundColor="#FFFFFF"/> <mx:HBox id="printAppBar" visible="false" x="149" y="5" width="150" backgroundColor="#FFFFFF" paddingLeft="6" paddingTop="3" paddingBottom="3"> <mx:Button label="PRINT" click="doPrint(FlexPrintJobScaleType.SHOW_ALL)" /> <mx:Button label="CLOSE" click="closePrintWindow()"/> </mx:HBox> <mx:Panel id="printPanel" visible="false" x="300" y="5" height="640" width="495" verticalScrollPolicy="off" horizontalScrollPolicy="off" borderAlpha="0" layout="absolute"> <mx:SWFLoader id="swfLoader"/> </mx:Panel> <!-- Print Preview Button --> <mx:LinkButton id="print" label="Print" click="takeSnapshot(myMap)"/>