I have an idea that this might be a problem with the asynchronous way methods get called in Flex. In other words even though code wise, the chart has been created before the automated image capture is called, somehow internally the chart is not complete. That's explains why the user triggered event of clicking the button works, but it doesn't explain why the automated calls to generate the image fail on the second and subsequent tries (since by then one would assume that the image has been created)
By the way, I am using callLater(saveAllSnapshots) for the automated code. Could someone please help me with this? Thanks! --- In [email protected], "netdeep" <deep...@...> wrote: > > I have two sections of code which generate a png file from a UIComponent. > Both seem > very similar except that one of them cuts the axis titles off for some > reason. The actual > image file is generated in Java, but the encoding happens here in flex. The > same code is > used in both calls to Java, though one is through a servlet (which then calls > a Java method) > and the other is through a direct call to the remote Java method. What is > going on? > > ImageSnapshot.defaultEncoder = PNGEncoder; > > public function saveAllSnapshots():void { > for (var i:int=0; i<flowLayout.getChildren().length; i++) { > var box:VBox = flowLayout.getChildAt(i) as VBox; > var cp:ChartPanel = box.getChildAt(2) as ChartPanel; > this.captureImg(cp, cp.title); > } > } > > // creates png ByteArray and sends it to a java remote object for saving > // This is the method that chops off the axis titles > private function captureImg(comp:UIComponent, name:String):void { > var imageSnap:ImageSnapshot = ImageSnapshot.captureImage(comp); > var imageByteArray:ByteArray = imageSnap.data as ByteArray; > imgSave.saveImage(imageByteArray, name+"-img.png"); > } > > // handle a click on the save image button > private function imgClickHandler(evt:MouseEvent):void { > var button:Button = evt.target as Button; > for (var i:int=0; i<flowLayout.getChildren().length; i++) { > var box:VBox = flowLayout.getChildAt(i) as VBox; > if (button == box.getChildAt(1)) { > saveSnapShot(box.getChildAt(2) as UIComponent); > break; > } > } > } > > // show image in a new window (this works) > private function saveSnapShot(comp:UIComponent):void { > var imageSnap:ImageSnapshot = ImageSnapshot.captureImage(comp); > var imageByteArray:ByteArray = imageSnap.data as ByteArray; > > var request:URLRequest = new URLRequest(imgServURL); > request.contentType="text/html"; > request.data = imageByteArray; > request.method = URLRequestMethod.POST; > navigateToURL(request, "_blank"); > } >

