Give users the ability to print all the options in a Flex Combobox.
Use FlexPrintJob and a PrintDataGrid.
I recently worked on a Flex application where one of the requirements was that the users have the ability to print the options in a Combobox. The following code shows how to do it. It can also be used to print the dataProvider for any component.
<?xml version="1.0" encoding="utf-8"?>
<mx:Application
xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute"><mx:Script><![CDATA[
import mx.printing.FlexPrintJobimport mx.printing.FlexPrintJobScaleType;import mx.controls.Alert;[
Bindable]private var measurements: Array = [{label:
'1/4"', data:.25},{label:
'1/2"', data:.5},{label:
'3/4"', data:.75},{label:
'1"', data:1},{label:
'1 1/4"', data:1.25},{label:
'1 1/2"', data:1.5},{label:
'1 3/4"', data:1.75},{label:
'2"', data:2},];private function printCombo():void{
var job:FlexPrintJob = new FlexPrintJob();if(!job.start()) //start job an open print dialog box{
//Handle cancellation for a smooth UIAlert.show(
"Printing cancelled.");return;}
else{
job.addObject(printDataGrid, FlexPrintJobScaleType.NONE);
job.send();
//this call is synchronousAlert.show(
"Sent to printer successfully.");}
}
]]>
</mx:Script><mx:Canvas><mx:HBox id="vbox" x="10" y="30" ><mx:ComboBox id="cboData" width="200" dataProvider="{measurements}" prompt="Measurements" /><mx:Button label="Print" click="printCombo()"/><mx:PrintDataGrid id="printDataGrid" dataProvider="{cboData.dataProvider}" visible="false" /></mx:HBox></mx:Canvas></mx:Application>
Live example w/ View Source: http://www.brentlamborn.com/examples/flex_printing/
Sample printed result: