Problem getting image size
I am loading an image into an image component dynamically on component
creation. The images are all different sizes for each instantiation of this
component. I am trying to set the size of the component to match the size of
the image. I have tried a couple of ways, and am now doing it with the
attached code.
However, the object is always larger than the image, which is causing me
problems. I have tried removing the minHeight/minWidth, but then nothing shows
at all. Any ideas appreciated, this is the last bug I have to fix...
<?xml version="1.0" encoding="utf-8"?>
<mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml" creationComplete="init()"
minWidth="200" minHeight="200" creationPolicy="all">
<mx:Script>
<![CDATA[
...
private function init():void {
itemImage.source = filePath;
itemImage.addEventListener(FlexEvent.DATA_CHANGE, setSize);
}
private function setSize():void {
this.width = itemImage.measuredWidth;
this.height = itemImage.measuredHeight;
}
...
]]>
</mx:Script>
<mx:Image id="itemImage" />
</mx:Canvas>
|