0

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

Craig Mc
  • 505
  • 1
  • 13
  • 30
  • The error I get is: ReferenceError: Error #1069: Property flexShape303 not found on spark.components.Group and there is no default value. Which I know to be an addressing error, the question is how do I get it to see and add these. – Craig Mc Nov 01 '11 at 09:41

1 Answers1

0

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);
kbgn
  • 856
  • 1
  • 7
  • 16
  • Hi, it turns out that Vbox, does not accept Element, it uses AddChild. I converted it to a Vgroup and that seems to have done the trick. I'm interested by the technique you used called getDefinitionByName? can you tell me more about it. Most of my problems stem from not being able to talk to elements I have created dynamically using array notation? – Craig Mc Nov 07 '11 at 04:28
  • You can read about getDefinitionByName @ http://www.emanueleferonato.com/2011/03/31/understanding-as3-getdefinitionbyname-for-all-eval-maniacs/ or http://www.mikechambers.com/blog/2006/06/22/actionscript-3-get-a-class-reference-by-class-name/ – kbgn Nov 07 '11 at 21:56