DataGrid Totals?

Hi,

I want to sum up a total of a specific column in a datagrid but am having problems, I’m using Flash MX 2004 Pro.

Here is what I have done:

Inserted a DataGrid, named it UserGrid.

Created a dynamic textfield called total.

I have the folllowing AS on frame 1:

[AS]
import mx.controls.gridclasses.DataGridColumn;
UserGrid.addColumn(new DataGridColumn(“Title”));
UserGrid.addColumn(new DataGridColumn(“Quantity”));
UserGrid.addColumn(new DataGridColumn(“Price”));

onClipEvent(enterFrame){
sum = 0
for(i=0; i<UserGrid.getLength() ; i++) {
trace(UserGrid.getItemAt(i).Price) //Here I output column values
sum += Number(UserGrid.getItemAt(i).Price)
}
total.text = sum
}
[/AS]

I also have an add button that has the following AS:

[AS]
on (release) {
UserGrid.addItem({Title:“Product 1”, Quantity:“1”, Price:“27”});
}
[/AS]

Now, when I press the add button it puts a new entry into the datagrid, but I want it to calculate the total of all the rows in the Price column and insert them into the textfield total.

Not sure if my script on frame 1 is correct to be honest, gives me this in the textfield at the moment:

[AS]
_level0.total
[/AS]

Any ideas?

Cheers,
Chris