0

I have a container displaying several elements and I want to create a bitmap representing some of them together.

Since I do not want to remove the elements from their owner, I use a second container in which I insert a bitmap created for each element. Then I produce a bitmap from this second container. The algorithm looks like this:

const selectionGroup:Group = new Group();

for each ( var element:UIComponent in selectedElements ) {

    const image:Image = new Image();
    image.x = element.x;
    image.y = element.y;
    image.source = createBitmapFrom( element );
    selectionGroup.addElement( image );
}

return createBitmapFrom( selectionGroup );

However, the final bitmap never contains anything unless I display the group somewhere. Eventually I can also remove it as soon as the creationComplete event is dispatched but I do not like this solution since it makes the interface to flicker.

I tried to insert the elements in a BoarderContainer instead of a Group, with creationPolicy set to "all", and calling createDeferedContent() before the final createBitmapFrom(), but the image is still transparent.

So, the next solution would be to compose the final bitmap from the various sub bitmaps, unless someone tells me how to capture a component that is never displayed.

How can I tell to Flex to create the content of the component without displaying it?

Julien
  • 2,139
  • 1
  • 19
  • 32
  • http://stackoverflow.com/questions/9670534/clone-an-image-in-flex-4-6/9671138#9671138 refer this link I think this would be what you are looking for – Triode Oct 31 '12 at 13:46
  • @rajesh.adhi it is good to create a bitmap from a displayed DisplayObject, but I do not think it would work if the DisplayObject is not added to stage. – Julien Oct 31 '12 at 14:17
  • 3
    You will need to add it to the display list so that Flex will lay out the components for "visual" display. Flex uses a complex set of rules to determine how the component will "truly" look when displayed so it needs to know where to put it before it knows what it will look like in that spot. You can add it to the display list and put it out of view so that it is not seen by the user (I think this is where your flicker you mentioned came from... the component was in view for a few milliseconds), but is rendered by Flex. Then once you get your Bitmap, remove it from the stage as you mentioned. – Jason Reeves Oct 31 '12 at 15:26

0 Answers0