Air HTML Component and HTML_RENDER event

572 Views Asked by At

We are currently using the mx:HTML component to render complex HTML pages (which was pretty disturbing..:)). For some reasons, we need, when the HTML is rendered, to capture an image of the displayed page. So i use the following code to do this :

on initialization :

frameHtml.addEventListener(Event.HTML_RENDER, cacheFrameHTML);

and the cacheFrameHTML function :

private function cacheFrameHTML(event:*):void {
...
cacheImage.source = new Bitmap( ImageSnapshot.captureBitmapData(frameHtml));
...
}

For some unknown reason, the result image is sometime completly blank. It seems that there is a short delay between HTML_RENDER event and effective rendering of the HTML component. I tried to delay the image capture with a timer which seems to work, but that is not pretty clean.

So my question is : - is there anyone who know a trick to only trigger the capture when the HTML frame is effectivly displayed? - at least, is there anyway to test if the result BitmapData is blank or have only white pixels?:b

Thanks a lot

Antoine

1

There are 1 best solutions below

1
On

Have you tried to use the callLater method?

The callLater() method queues an operation to be performed for the next screen refresh, rather than in the current update

private function cacheFrameHTML(event:*):void {
...
callLater(saveImage);
...
}

private function saveImage():void
{
cacheImage.source = new Bitmap( ImageSnapshot.captureBitmapData(frameHtml));
}