Flex 4 Printing by Adding dynamic items in a print area (AKA. how do I add dynamically named elements to another element on the fly)

StackOverflow https://stackoverflow.com/questions/7964394

سؤال

I have a number of items I add to the stage dynamically.

These are called flexShapeXXX where xxx is typically a unique ID.

Now I have created a component to store them in for printing, that I can treat as a virtual page so I can lay out stuff for printing.

This looks like this:

    <?xml version="1.0"?>
<!-- myComponents\MyPrintView.mxml -->
<mx:VBox xmlns:fx="http://ns.adobe.com/mxml/2009" 
         xmlns:s="library://ns.adobe.com/flex/spark" 
         xmlns:mx="library://ns.adobe.com/flex/mx" 
         backgroundColor="#FFFFFF" 
         height="300" width="500" 
         paddingTop="50" paddingLeft="50" paddingRight="50">


</mx:VBox>

Now so far so good I then take my little print are vbox component:

var formPrintView:MyPrintView = new MyPrintView();
formPrintView.width = printJob.pageWidth - 50;
formPrintView.height = printJob.pageHeight - 50;    
addElement(formPrintView);

This works fine it add a nice space to work in.

Now I want to be able to do something like this:

formPrintView.addElement(dashPreview["flexShape" + TheID]);
printJob.addObject(formPrintView);

That part fails.

So my question is how do I addelements from the stage via dynamic names. So that I may print them.

Please and thank you for any help you can offer.

Craig

هل كانت مفيدة؟

المحلول

Can you please try my solution below and let me know if it doesnt work. Let us assume you have an UI Component : Page1

var page1:VBox = new VBox();

// Convert class name to Class object.
var cls:Class = getDefinitionByName(page1) as Class;
// Create a new instance of the class.
var instance:UIComponent = new cls();

var formPrintView:MyPrintView = new MyPrintView();
formPrintView.width = printJob.pageWidth - 50;
formPrintView.height = printJob.pageHeight - 50;   
formPrintView.addElement(instance);
printJob.addObject(formPrintView);
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top