我需要一些帮助。我对actionscript很陌生,我想做的是从数组中计算苹果的数量,然后在主函数中跟踪它。现在我在返回时遇到错误,该错误是1067: Implicit coercion of a value of type of String to an unrelated type Number。现在我试图切换数字和字符串,但我仍然得到错误。
public class extends Sprite
{
public function()
{
var fruitNames:Array = ["apple", "peach","banana","pear","guava","apple","peach"];
var totalApples:Number = countingApples(fruitNames);
trace("You have " + totalApples);
}
private function countingApples(fruitNames:Array):Number
{
var total:String = "apple";
for(var i:uint=0; i<7; i++)
{
total += Number[i];
}
return total;
}
}