开发者

Flex 4 Printing Error with dynamic components

I have a set of components that are added to my Flex 4 stage dynamically.

Problem 1: How do I address these objects when adding them to print.I cant generate objects on the fly and append them because then the print manager does not wait for the dynamic data to populate.

I currently use the following code to address items dynamically which fails:

public function PrintDashPreview():void{
    var ItemsDrawn:int = 0;
    var printJob:FlexPrintJob = new FlexPrintJob();
    if(printJob.start()){
        for each (var item:Object in GetDashBoardPreviewItems.lastResult.DashboardItem)
        {
            ItemsDrawn ++
            this.addElement(dashPreview["flexShape" + TheID]);
            printJob.addObject(dashPreview["flexShape" + TheID]);
            this.removeElement(dashPreview["flexShape" + TheID]);

        }
        printJob.send()

    Alert.show('Sent: ' + ItemsDrawn + ' items to page for printing.','Print Progress Debug');
    }
}

How can I tell flex to grab these specific items and add them to the print job.

Problem 2:

How do I tell flex to lay each item out one below the other 2 per page.

Please and thank you for any help you can provide开发者_如何学Go.

Regards Craig Mc


The recipe for printing dynamic content usually goes like this:

(1) Start the printJob:

printJob = new FlexPrintJob();
printJob.printAsBitmap = false;
printJob.start();

(2) Obtain the print page dimensions. Use it if you have overflowing content:

printerPageHeight = printJob.pageHeight;
printerPageWidth = printJob.pageWidth;

(3) Create all of the dynamic objects and wait for the corresponding CREATION_COMPLETE events:

var componentsToBeInitialized:Number = 0;
var pages:Array = [];
for each (var itemData:Object in dataProvider) {
    var component:UIComponent = new PageComponent();
    someContainerOnTheDisplayList.addChild(component);
    component.data = itemData;
    componentsToBeInitialized ++;
    pages.push(component);
    component.addEventListener(FlexEvent.CREATION_COMPLETE, handlePageCompletion);
}

(4) Waiting for all CREATION_COMPLETE events:

function handlePageCompletion(e:Event):void {
    componentsToBeInitialized --;
    if (componentsToBeInitialized == 0)
        printAllPages();
}

(5) Print the pages:

function printAllPages():void {
   for each (var printPage:UIComponent in pages) {
   printJob.addObject(printPage);
   }         
   printJob.send();
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜