So, I've completed my investigation into this issue. The problem is
"unsolvable" in the sense that there is no general way for mx:Image to
determine the size of the image until it has been loaded, which is too
late for the way renderers work. Therefore, we will not be able to make
any improvements to the code in Flex 3 to make this problem go away.
It will be up to each developer to code up how to guess at or actually
determine the size of the image before it is finished loading. Examples
might be:
1) Adding image width/height as fields to the dataprovider.
2) Encoding the image width/height from the url of the image
(myThumbNail800x500.jpg)
3) Having a table or other lookup function to determine width/height
based on the url:
4) Guessing at a reasonable size for the image and caching the true
value once it comes in. Below is an example:
<mx:DataGridColumn dataField="info" headerText="Image" >
<mx:itemRenderer>
<mx:Component>
<mx:Image complete="cacheSize()" >
<mx:Script>
<![CDATA[
private var sizeMap:Object = {};
private var loadPending:Boolean = false;
//
override public function set source(value:Object):void
{
super.source = value;
loadPending = true;
}
override protected function measure():void
{
super.measure();
if (loadPending)
{
if (sizeMap[source])
measuredHeight = sizeMap[source];
else
measuredHeight = 50; // pick a reasonable number here
}
}
private function cacheSize():void
{
sizeMap[source] = content.height;
loadPending = false;
}
]]>
</mx:Script>
</mx:Image>
</mx:Component>
</mx:itemRenderer>
</mx:DataGridColumn>
Option 4 has some first-time glitches, but stabilizes scrolling
behavior.
I'm sure there are other options as well, but, depending on your
situation, one of these four might suffice.
-Alex
________________________________
From: [email protected] [mailto:[EMAIL PROTECTED] On
Behalf Of Alex Harui
Sent: Friday, September 07, 2007 3:47 PM
To: [email protected]
Subject: RE: [flexcoders] Re: Unwanted scrollbars on my List
itemRenderer--measure() help?
Yes, you should deal with listData in commitProperties or later. That's
why it is only one level of hairy.
________________________________
From: [email protected] [mailto:[EMAIL PROTECTED] On
Behalf Of Tracy Spratt
Sent: Friday, September 07, 2007 3:08 PM
To: [email protected]
Subject: RE: [flexcoders] Re: Unwanted scrollbars on my List
itemRenderer--measure() help?
"listData is available when ... commitProperties runs" and
commitProperties runs after set data(), yes? So if a renderer needs to
use listData, it should do that work in commitProperties. Right? That
clears up some questions I had about ListItemRenderer.
That's 0.2 orders of magnitude less hairy.
Tracy
________________________________
From: [email protected] [mailto:[EMAIL PROTECTED] On
Behalf Of Alex Harui
Sent: Friday, September 07, 2007 5:52 PM
To: [email protected]
Subject: RE: [flexcoders] Re: Unwanted scrollbars on my List
itemRenderer--measure() help?
The "rules" are:
listData is set for you and should never be modified by the renderer.
listData is available when the dataChange event fires or
commitProperties runs
explicitWidth should be set so use that to your advantage.
Is there any way you can know by the url of the image what its height
will be?
________________________________
From: [email protected] [mailto:[EMAIL PROTECTED] On
Behalf Of David Ham
Sent: Friday, September 07, 2007 2:43 PM
To: [email protected]
Subject: [flexcoders] Re: Unwanted scrollbars on my List
itemRenderer--measure() help?
> It should only be one level of hairy, not three...
LOL. Sorry, I wax hyperbolic late in the day, when the caffeine has
jacked me up and Flex has dragged me behind its car for a ways. I'll
dig around in measure() and see what I can do.
Do I need to worry about setting listData when I subclass
ListItemRenderer? I am getting null object reference errors around it...
OK
DAH