royale-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Carlos Rovira <carlosrov...@apache.org>
Subject using the "UIBase.getElementAt" method
Date Thu, 16 Aug 2018 18:23:02 GMT
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

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message