I am using the Flash code provided on the web. Im modifying it as to differentiate the colour of odd numbered row Background and the even one. But I cant get access to the data.index. How do I get access to the index?
import fl.controls.TileList;
import fl.core.UIComponent;
import fl.data.DataProvider;
import fl.events.ListEvent;
import flash.display.Sprite;
import flash.events.Event;
public class CellRendererExample extends Sprite
{
public function CellRendererExample() {
var index:int;
var dp:DataProvider = new DataProvider();
var totalEntries:uint = 42;
var i:uint;
for(i=0; i<totalEntries; i++) {
dp.addItem( { label:"Item "+i ,index:i} );
}
var myTileList = new TileList();
myTileList.dataProvider = dp;
myTileList.allowMultipleSelection = true;
myTileList.columnWidth = 125;
myTileList.rowHeight = 30;
myTileList.columnCount = 1;
myTileList.rowCount = 6;
myTileList.move(10,10);
myTileList.direction = "VERTICAL";
for(i=0; i<totalEntries; i++) {
if (dp.label[i].index%2==0){
myTileList.setStyle('cellRenderer', MyRenderer); }
else{
myTileList.setStyle('cellRenderer', MyAnotherRenderer);
}
}
addChild(myTileList);
}
This line is completely wrong:
DataProvider just contains your items, similar to Array.
label[i]won't return anything, andindexis not a property of that object (labelandindexare properties of the object that you put into the DataProvider).First, your
ivariable is actually the index. You can check ifi % 2 == 0. If you want any specific information from the DataProvider (you put different indexes in the elements), you could usedp.getItemAt(i)-> this will give you each item, and you can check it's properties:dp.getItemAt(i).index % 2 == 0.