Setting the RowCount and ColumnCount in a Flex 3 TileList
I'm using the TileList in a Flex 3 website. I need to set the rowCount and columnCount to factors of the total number of items in my array. For example, let's say that there are 15 items in my array. Then, I'd like to set the rowCount to 3 and the columnCount to 5 (3x5=15). Or if I had 16 items in the array, then I'd like to set the rowCount to 4 and th开发者_JAVA百科e columnCount to 4 (4x4=16). The problem is that the length of the array varies. It's pulled from a database.
Any suggestions on how to handle this problem?
Thank you.
-Laxmidi
I suppose you already have the process finished up to a point, where you load your items into an ArrayCollection (lets call it A), which is a dataProvider of the TileList.
In that case, you can just add something like this into the service callback, where the AC gets created:
for (var i:int=Math.sqrt(A.length)+1e-9;i>0;i-=1)
if (A.length%i==0)
{
tileList.columnCount=i;
tileList.rowCount=A.length/i;
break;
}
This code gives you RxC TileList where R=C if A.length is a square, otherwise it will be as close to square as possible, while R>C (which is usually desirable due to vertical vs. horizontal scroll).
精彩评论