<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical"
creationComplete="init(event)"
pageTitle="Printing A DataGrid That Spans Multiple Pages" viewSourceURL="srcview/index.html">
<mx:Script>
<![CDATA[
import mx.controls.Alert;
import mx.events.FlexEvent;
import flash.events.Event;
import flash.net.URLLoader;
import flash.net.URLRequest;
import flash.utils.*;
import mx.utils.ObjectUtil;
import mx.collections.XMLListCollection;
import mx.printing.FlexPrintJob;
import mx.printing.FlexPrintJobScaleType;
[Bindable]
private var _submissionsXML:XMLListCollection;
private function init(e:FlexEvent):void {
var request:URLRequest = new URLRequest('data/submissions.xml');
var loader:URLLoader = new URLLoader();
loader.addEventListener(Event.COMPLETE, completeListener);
loader.addEventListener(IOErrorEvent.IO_ERROR, ioErrorListener);
loader.load(request);
}
private function ioErrorListener(event:IOErrorEvent):void {
Alert.show("Failure! Unable to load the data file. Contact Bruce Phillips, webmaster@BrucePhillips.name to report this problem.\n" + event.text );
}
private function completeListener(event:Event):void
{
var loader:URLLoader = event.target as URLLoader;
var _xml:XML = new XML(loader.data);
var _xmlList:XMLList = _xml.row ;
_submissionsXML = new XMLListCollection(_xmlList);
}
public function doPrint():void {
var printJob:FlexPrintJob = new FlexPrintJob();
if ( printJob.start() ) {
var thePrintView:MyPrintView = new MyPrintView();
addChild(thePrintView);
thePrintView.printDG.dataProvider = submissionsDG.dataProvider;
thePrintView.width=printJob.pageWidth;
thePrintView.height=printJob.pageHeight;
if( thePrintView.printDG.validNextPage == false )
{
printJob.addObject(thePrintView);
}
else
{
printJob.addObject(thePrintView);
while ( thePrintView.printDG.validNextPage ) {
thePrintView.printDG.nextPage();
printJob.addObject(thePrintView);
}
}
removeChild(thePrintView);
printJob.send();
}
}
]]>
</mx:Script>
<mx:Label text="Click the button to print the results below." fontSize="14"/>
<mx:Button label="Print" width="150" click="doPrint()" fontSize="12"/>
<mx:DataGrid width="90%" height="90%" variableRowHeight="true" wordWrap="true"
dataProvider="{_submissionsXML}" id="submissionsDG">
<mx:columns>
<mx:DataGridColumn dataField="MAINPRESENTER" headerText="Main Presenter" wordWrap="true" width="150" />
<mx:DataGridColumn dataField="PRES_TITLE" headerText="Title" wordWrap="true" />
</mx:columns>
</mx:DataGrid>
</mx:Application>