用Flash里的AS编了一个购物数据,运行时出问题,谁来解决?
//创建一个购物车数据,创建一个循环,用于跟踪每一个数据块,并打印出总金额var shop:Object = new Object();
//创建一个联合数组
shop.mp3 = {totalshop_num:0, shopcharge:0};
shop.播放器 = {totalshop_num:0, shopcharge:0};
shop.耳机 = {totalshop_num:0, shopcharge:0};
shop.充电器 = {totalshop_num:0, shopcharge:0};
var totalmoney:Number = 0;
var goods:Array = new Array();
goods.push({id:"ip300", type:"mp3", charge:299});
goods.push({id:"ip130", type:"播放器", charge:49});
goods.push({id:"ib300", type:"耳机", charge:29});
goods.push({id:"a250", type:"充电器", charge:69});
var currentgoods:String;
var numshop:Number = goods.length;
trace("商品数为:"+numshop);
for (var i:Number = 0; i<numshop; i++) {
trace(goods[i].type);
currentgoods = goods[i].type;
//当前的商品类型
shop[current].totalshop_num += 1;
//该商品购买数量
shop[current].shopcharge = goods[i].charge*shop[current].totalshop_num;
//当前商品总价
totalmoney += shop[current].shopcharge;
//当前总价
}
for (gen in shop) {
trace("the goods is :"+gen);
trace("the goods num is:"+shop[gen].totalshop_num);
trace("this goods money is:"+totalmoney);
trace("----------------------------------------");
}
trace(totalmoney);
//测试时,总价格不能累加,不知道哪里出错了
[ 本帖最后由 魏兴耀 于 2010-3-8 19:00 编辑 ]