Hi,
I'm using the getElementAt method to create an IContentView and have a hard
time when there's no elements in the container.
I final have this working in the following way: (this is part of
TBodyContentArea.as in Jewel in order to see the full code, I remove the
parts that are not needed to make this less verbose)
public function addItemRendererAt(renderer:IItemRenderer, index:int):void
{
....
var row:TableRow;
try
{
row = getElementAt(r.rowIndex) as TableRow;
//this if only happens if numElemens == 0, so throw an
Error to make a new TableRow in the catch section
if(row == null)
{
row = new TableRow();
addElementAt(row, r.rowIndex, false);
}
}
catch (error:Error)
{
// this is the only way I found to do this when checking
getElementAt() for an index that doen't exists.
row = new TableRow();
addElementAt(row, r.rowIndex, false);
}
row.addElementAt(tableCell, r.columnIndex, true);
....
}
Maybe there's other way to do this?
I expect to do
var row:TableRow = getElementAr(r.index) as TableRow;
if(row)
{
// do things when the element exists
}
else
{
// create the row and add it to container
}
but this only work for the first row, (index = 0), for index = 1 it crash
since
the code in UIBase.as is
public function getElementAt(index:int):IChild
{
COMPILE::SWF
{
return $getChildAt(index) as IChild;
}q
COMPILE::JS
{
var children:Array = internalChildren();
if (children.length == 0)
{
return null;
}
return children[index].royale_wrapper;
}
}
and when index = 1 the final return is unfixed since children[1] doesn't
exists.
Maybe there's another way to do this?
thanks
--
Carlos Rovira
http://about.me/carlosrovira