views:

17

answers:

1

Hi,

I have a Adobe Flex project in which resides the following layout markup.

<s:TileGroup id="grid" width="467" height="467" requestedRowCount="15" requestedColumnCount="15" horizontalGap="0" verticalGap="0" verticalAlign="middle" name="tg">
    <s:BorderContainer width="31" height="31" name="container">
         <s:Label text="999" verticalAlign="middle" textAlign="center" paddingLeft="0" paddingRight="2" paddingBottom="0" paddingTop="0" width="29" height="29" click="Clicked(event)"/>
    </s:BorderContainer>
    <s:BorderContainer width="31" height="31" name="container">
         <s:Label text="999" verticalAlign="middle" textAlign="center" paddingLeft="0" paddingRight="2" paddingBottom="0" paddingTop="0" width="29" height="29" click="Clicked(event)"/>
    </s:BorderContainer>
...
...
</s:TileGroup>

I would like to be able to get the value of each of the text (as int) attribute in the s:Label element. I tried this:

var count:int = 0;

for each (var b:BorderContainer in grid)
{
    count += parseInt((b.getElementAt(0) as Label).text);
}

But that does not work. In fact, when debugging "b" is always null even though "grid.getElementAt(0)" returns a BorderContainer.

I would appreciate any help anyone can provide me in solving my problem.

Thanks,

Kamal.

+1  A: 

You need to iterate over the group's elements like that:

var count:int = 0;

for (var i:int = 0; i < grid.numElements; i++)
{
    var b:BorderContainer = BorderContainer(grid.getElementAt(i));
    count += parseInt(Label(b.getElementAt(0)).text);
}

In case there are not only BorderContainer's and Label's you will need to do a little type checking (casting with 'as' and checking for null)...

Gerhard
Thank you Gertshi! this did the trick.
Kamal