Great Alex, that worked! :)
simplified code is now:
var row:TableRow;
if(r.rowIndex > numElements -1)
{
row = new TableRow();
addElementAt(row, r.rowIndex, false);
}
else
{
row = getElementAt(r.rowIndex) as TableRow;
}
Many thanks! :)
Carlos
El vie., 17 ago. 2018 a las 8:19, Alex Harui (<[email protected]>)
escribió:
> Are you trying to getElementAt for an index > numElements? That's
> generally the test to perform:
>
> If (index > numElements - 1)
> addElement(newChild)
> else
> addElementAt(newChild, index);
>
> HTH<
> -Alex
>
> On 8/16/18, 11:23 AM, "Carlos Rovira" <[email protected]> wrote:
>
> 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
>
> https://na01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fabout.me%2Fcarlosrovira&data=02%7C01%7Caharui%40adobe.com%7C6853a1036c49487d20a708d603a5570d%7Cfa7b1b5a7b34438794aed2c178decee1%7C0%7C0%7C636700406000833577&sdata=qW%2FOxy5pez2AHwTTXixuBITpdRAmC%2BX7Lfk8hSyYCdg%3D&reserved=0
>
> --
>
> <https://na01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fabout.me%2Fcarlosrovira&data=02%7C01%7Caharui%40adobe.com%7C6853a1036c49487d20a708d603a5570d%7Cfa7b1b5a7b34438794aed2c178decee1%7C0%7C0%7C636700406000833577&sdata=qW%2FOxy5pez2AHwTTXixuBITpdRAmC%2BX7Lfk8hSyYCdg%3D&reserved=0>
>
> <https://na01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fabout.me%2Fcarlosrovira&data=02%7C01%7Caharui%40adobe.com%7C6853a1036c49487d20a708d603a5570d%7Cfa7b1b5a7b34438794aed2c178decee1%7C0%7C0%7C636700406000833577&sdata=qW%2FOxy5pez2AHwTTXixuBITpdRAmC%2BX7Lfk8hSyYCdg%3D&reserved=0>
>
> <https://na01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fabout.me%2Fcarlosrovira&data=02%7C01%7Caharui%40adobe.com%7C6853a1036c49487d20a708d603a5570d%7Cfa7b1b5a7b34438794aed2c178decee1%7C0%7C0%7C636700406000833577&sdata=qW%2FOxy5pez2AHwTTXixuBITpdRAmC%2BX7Lfk8hSyYCdg%3D&reserved=0>
> Carlos Rovira
>
> <https://na01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fabout.me%2Fcarlosrovira&data=02%7C01%7Caharui%40adobe.com%7C6853a1036c49487d20a708d603a5570d%7Cfa7b1b5a7b34438794aed2c178decee1%7C0%7C0%7C636700406000833577&sdata=qW%2FOxy5pez2AHwTTXixuBITpdRAmC%2BX7Lfk8hSyYCdg%3D&reserved=0>
>
> <https://na01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fabout.me%2Fcarlosrovira&data=02%7C01%7Caharui%40adobe.com%7C6853a1036c49487d20a708d603a5570d%7Cfa7b1b5a7b34438794aed2c178decee1%7C0%7C0%7C636700406000833577&sdata=qW%2FOxy5pez2AHwTTXixuBITpdRAmC%2BX7Lfk8hSyYCdg%3D&reserved=0>
> http://about.me/carlosrovira
>
>
>
>