Hi,
I've been trying to get the MultiLineCell Renderer below to automatically resize the height of rows based on content of row. I've had no luck so far. Any ideas anyone?
I got this from liveDocs a Nigel post:
http://livedocs.macromedia.com/flash/mx2004/main/wwhelp/wwhimpl/common/html/wwhelp.htm?context=Flash_MX_2004_Documentation&file=04_com55.htm[script]
class MultiLineCell extends mx.core.UIComponent
{
var multiLineLabel; // : TextField - the label we're going to use for text.
var owner; // The row that contains this cell
var listOwner; // the List/grid/tree that contains this cell
function MultiLineCell()
{
}
// UIObject expects you to fill in createChildren by instantiating
// all the movie clip assets you might need upon initialization.
// for us, it's just a label.
function createChildren(Void) : Void
{
// createLabel is a useful method of UIObject - all components use this
var c = multiLineLabel = createLabel("multiLineLabel", 0);
//don't worry too much about this - it links the style of the label to the
//style of the grid itself
c.styleName = listOwner;
c.selectable = false;
c.tabEnabled = false;
c.background = false;
c.border = false;
c.multiline = true;
c.wordWrap = true;
//added to autosize this field
c.autosize = true;
}
// note that, by extending UIComponent, we get setSize for free
// however, UIComponent expects us to implement size().
// Assume __width and __height are set for us now.
// We're going to grow the cell to fit the whole rowHeight
function size(Void) : Void
{
// __width and __height are the underlying variables of the getter
// setters .width and .height. Not strictly kosher, but I'm fond of small
// performance shortcuts in cases where it's reasonably safe.
var c = multiLineLabel;
c._width = __width;
c._height = __height;
}
function getPreferredHeight(Void) : Number
{
//k, a little voodoo here. we know the cell will be given a property, "owner",
// which will be the row. We always prefer that the cell take up most of the row's height
return owner.__height - 4;
}
function setValue(suggested:String, item:Object, selected:Boolean) : Void
{
//not much to do here. Feed the label!
multiLineLabel.text = suggested;
}
//function getPreferredWidth :: only really necessary for menu
}
[/script]