From ce7a1c9cb845f0d171f2869fe6ded6e5ac84697e Mon Sep 17 00:00:00 2001 From: Ray Greenwell Date: Fri, 8 Aug 2008 23:11:40 +0000 Subject: [PATCH] Added getCellCount() and getCellAt(), inspired by SimpleGrid. git-svn-id: svn+ssh://src.earth.threerings.net/nenya/trunk@618 ed5b42cb-e716-0410-a449-f6a68f950b19 --- src/as/com/threerings/flex/GridUtil.as | 29 ++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/src/as/com/threerings/flex/GridUtil.as b/src/as/com/threerings/flex/GridUtil.as index b8a7bd58..c6f37244 100644 --- a/src/as/com/threerings/flex/GridUtil.as +++ b/src/as/com/threerings/flex/GridUtil.as @@ -84,5 +84,34 @@ public class GridUtil row.addChild(item); return item; } + + /** + * Get the number of cells in a grid. + */ + public static function getCellCount (grid :Grid) :int + { + var count :int = 0; + for (var ii :int = 0; ii < grid.numChildren; ii++) { + count += (grid.getChildAt(ii) as GridRow).numChildren; + } + return count; + } + + /** + * Return the contents of the specified cell. Not super fast, as it + * checks each row in order. + */ + public static function getCellAt (grid :Grid, index :int) :UIComponent + { + for (var ii :int = 0; ii < grid.numChildren; ii++) { + var row :GridRow = grid.getChildAt(ii) as GridRow; + if (index < row.numChildren) { + return (row.getChildAt(index) as GridItem).getChildAt(0) as UIComponent; + } else { + index -= row.numChildren; // and then on to the next row + } + } + return null; // never found it. throw an out-of-range error? + } } }