Hi,
How can I modify the following working code to get data from external XML file?
import fl.controls.DataGrid;
import fl.controls.TextInput;
import fl.controls.dataGridClasses.DataGridColumn;
import fl.data.DataProvider;
var dp:DataProvider = new DataProvider();
dp.addItem({item:“Asparagus”, price:0.53});
dp.addItem({item:“Brussel Sprouts”, price:0.27});
dp.addItem({item:“Cabbage”, price:0.04});
dp.addItem({item:“Cauliflower”, price:0.16});
var itemTextInput:TextInput = new TextInput();
itemTextInput.move(10, 10);
itemTextInput.addEventListener(Event.CHANGE, changeHandler);
addChild(itemTextInput);
var itemCol:DataGridColumn = new DataGridColumn(“item”);
itemCol.headerText = “Vegetable:”;
var priceCol:DataGridColumn = new DataGridColumn(“price”);
priceCol.headerText = “Price (per/lb):”;
priceCol.labelFunction = priceLabelFunction;
priceCol.sortOptions = Array.NUMERIC;
var myDataGrid:DataGrid = new DataGrid();
myDataGrid.addColumn(itemCol);
myDataGrid.addColumn(priceCol);
myDataGrid.dataProvider = dp;
myDataGrid.width = 200;
myDataGrid.rowCount = myDataGrid.length;
myDataGrid.move(10, 40);
addChild(myDataGrid);
function priceLabelFunction(item:Object):String {
return “$” + Number(item.price).toFixed(2);
}
function changeHandler(event:Event):void {
var arr:Array = dp.toArray();
var filteredArr:Array = arr.filter(filterDataProvider);
myDataGrid.dataProvider = new DataProvider(filteredArr);
}
function filterDataProvider(obj:Object, idx:int, arr:Array):Boolean {
var txt1:String = itemTextInput.text;
var txt2:String = obj.item.substr(0, txt1.length);
if (txt1.toLowerCase() == txt2.toLowerCase()) {
return true;
}
return false;
}
Because I have a lot of data which can be easily entered/edited.
Thanks for any help.