First import mx. printing. FlexPrintJob;
Import mx. printing. PrintAdvancedDataGrid;
1. Use FlexPrintJob to print
1. If there is no paging or drop-down box
Copy codeThe Code is as follows: public function doPrint (): void {
Var printer: FlexPrintJob = new FlexPrintJob ();
If (printer. start ()){
Printer. addObject (body );
Printer. send ();
}
}
This method can be used below. Because I am using Flex3, there is no label "PrintDataGrid" in Flex3, and only "PrintAdvancedDataGrid ". The following three methods are used: ("PrintAdvancedDataGrid", "AdvancedDataGrid", and "DataGrid"). Remember that the above method is only applicable to a single page (with less data) and there is no drop-down box.Copy codeThe Code is as follows: <mx: PrintAdvancedDataGrid id = "body" x = "188" y = "232">
<Mx: columns>
<Mx: AdvancedDataGridColumn dataField = "username"/>
<Mx: AdvancedDataGridColumn dataField = "password"/>
</Mx: columns>
</Mx: PrintAdvancedDataGrid>
Bytes --------------------------------------------------------------------------------------
[/Code]
<Mx: AdvancedDataGrid id = "body" x = "188" y = "232">
<Mx: columns>
<Mx: AdvancedDataGridColumn dataField = "username"/>
<Mx: AdvancedDataGridColumn dataField = "password"/>
</Mx: columns>
</Mx: AdvancedDataGrid>
[/Code]
Bytes -----------------------------------------------------------------------------------------Copy codeThe Code is as follows: <mx: DataGrid id = "body" x = "188" y = "232">
<Mx: columns>
<Mx: DataGridColumn dataField = "username"/>
<Mx: DataGridColumn dataField = "password"/>
</Mx: columns>
</Mx: DataGrid>
Certificate ----------------------------------------------------------------------------------------------------------------------------------------------------------
If you want to use the paging effect, you must use the label "PrintAdvancedDataGrid" (the label in Flex3) to achieve the paging effect.Copy codeThe Code is as follows: private function doPrint (): void {
Var PrintJob: FlexPrintJob = new FlexPrintJob ();
If (PrintJob. start ()){
AddChild (body );
// Set the print view attributes
While (true ){
PrintJob. addObject (body );
If (body. validNextPage ){
Body. nextPage ();
} Else {
Break;
}
}
}
PrintJob. send ();
}
The corresponding label of this method is:Copy codeThe Code is as follows: <mx: PrintAdvancedDataGrid id = "body" x = "188" y = "232">
<Mx: columns>
<Mx: AdvancedDataGridColumn dataField = "username"/>
<Mx: AdvancedDataGridColumn dataField = "password"/>
</Mx: columns>
</Mx: PrintAdvancedDataGrid>