I want to create a snapshot that composes several components in a different way than they are displayed to the user.
Let's say the layout on screen looks like this:
<s:VGroup>
<s:HGroup id="dynamicPopulatedGroup" />
<mx:TabNavigator id="tabs">
<s:NavigatorContent> <mx:LineChart id="chart1"/> </s:NavigatorContent>
<s:NavigatorContent> <mx:LineChart id="chart2"/> </s:NavigatorContent>
</mx:TabNavigator>
<mx:Legend id="legend" />
<s:Button id="bSnapshot" />
</s:VGroup>
But the "screenshot" should be layed out like:
<s:VGroup>
<s:Label>Some Title Text</s:Label>
<mx:LineChart>The currently selected tab's chart</mx:LineChart>
<s:HGroup>
<s:HGroup id="dynamicPopulatedGroup" />
<mx:Legend id="legend" />
</s:HGroup>
</s:VGroup>
This is a simplified example but it illustrates the main issue I am trying to accomplish, how to manipulate visual elements within a sandbox without affecting the elements themselves on the screen.
I tried to do this by creating a new Group
and adding the various components in code, then taking the screenshot. However this actually removes the components from their original places in the visual tree. Once this is finished running, the entire component is corrupted. Could it be that I need to create copies of these components first?
var g:VGroup = new VGroup();
// label
var l:Label = new Label(); l.text = "some title";
g.addElement(l);
// chart
g.addElement(NavigatorContent(tabs.selectedChild).getElementAt(0)); // chart
// legend, etc.
var hgrp:HGroup = new HGroup(); hgrp.addElement(dynamicPopulatedGroup); hgrp.addElement(legend);
g.addElement(hgrp);
ImageSnapshot.captureBitmapData(g);
// then do stuff with bitmap...