Need help with count total function

Hi…

okay I just need help with my totalcount function…the ideas is user can click how many items then it will be add in datagrid component…so my problems is I can’t make total sum for the cost of product… I mean like

the total sum value suppose to incrementing everytime the podducts being add…eg;

       100
     1000
      200
      100

total :1400

So how to achieve it?..maybe some little guide would be appreciate…

here’s my AS so far


stop();

var productArr:Array = [["tshirt","100"],["jeans","1000"],["shoes","200"]];

createEmptyMovieClip("paper",1);
for (var i = 0;i<productArr.length;i++){
	var mc = paper.attachMovie("item","item"+i,100+i);
	mc.ivar = i;
	mc._x = 100;
	mc._y = 50+(mc._width*i);
	mc.pro.text = productArr*[0];
	mc.cost.text = productArr*[1];
	mc.onPress = adddt;
}

// Add columns to grid and add data.
function adddt(){
	var item_obj:Object = {Product:productArr[this.ivar][0], Cost:productArr[this.ivar][1]};
	my_dg.addItem(item_obj);
	countTotal(productArr[this.ivar][1]);
}

//function calculate total
totalArr = [];
//this portion are little bit messy..and having problems
//really need help with it...
function countTotal(val){
	var totalval = 0; 
	totalArr.push(val);
	for(j=0;j<totalArr.length;j++){
		total.text = totalval + totalArr[j];
	}

}
   

tq in advanced