语法错误1084无论我做什么

时间:2012-08-04 19:36:59

标签: actionscript-3 syntax

我正在尝试为游戏制作工具...... 按下按钮会在计算后得出一些结果。该守则尚未完成,但不必提供错误。这是代码:

import flash.events.MouseEvent;
//-----------------------variables------------------------

var iPPP1:String;
var iPPP2:String;
var iPPP3:String;
var iPPP4:String;
var iPPP5:String;
var iPPP6:String;
var iPPP7:String;
var iCntbonus:String;
var iRawPrice:String;
var iAverSal:String;
var iTax:String;
var iNoC7:String;
var iNoC6:String;
var iNoC5:String;
var iNoC4:String;
var iNoC3:String;
var iNoC2:String;
var iNoC1:String;
var iEm7:String;
var iEm6:String;
var iEm5:String;
var iEm4:String;
var iEm3:String;
var iEm2:String;
var iEm1:String;
var iRaw5:String;
var iRaw4:String;
var iRaw3:String;
var iRaw2:String;
var iRaw1:String;
var apotelesma:Number;
var bonus:Number;
var i1:Number;
var i2:Number;
var i3:Number;
var i4:Number;
var i5:Number;
var i6:Number;
var i7:Number;

//------------------------restricts------------------------

PPP1.restrict = "0-9\\.";
PPP2.restrict = "0-9\\.";
PPP3.restrict = "0-9\\.";
PPP4.restrict = "0-9\\.";
PPP5.restrict = "0-9\\.";
PPP6.restrict = "0-9\\.";
PPP7.restrict = "0-9\\.";
Cntbonus.restrict = "0-5";
RawPrice.restrict = "0-9\\.";
AverSal.restrict = "0-9\\.";
Tax.restrict = "0-9";
NoC7.restrict = "0-9";
NoC6.restrict = "0-9";
NoC5.restrict = "0-9";
NoC4.restrict = "0-9";
NoC3.restrict = "0-9";
NoC2.restrict = "0-9";
NoC1.restrict = "0-9";
Em7.restrict = "0-9";
Em6.restrict = "0-9";
Em5.restrict = "0-9";
Em4.restrict = "0-9";
Em3.restrict = "0-9";
Em2.restrict = "0-9";
Em1.restrict = "0-9";
Raw5.restrict = "0-9";
Raw4.restrict = "0-9";
Raw3.restrict = "0-9";
Raw2.restrict = "0-9";
Raw1.restrict = "0-9";

//-------------------------------borders----------------------------

PPP1.border = true;
PPP2.border = true;
PPP3.border = true;
PPP4.border = true;
PPP5.border = true;
PPP6.border = true;
PPP7.border = true;
Cntbonus.border = true;
RawPrice.border = true;
AverSal.border = true;
Tax.border = true;
NoC7.border = true;
NoC6.border = true;
NoC5.border = true;
NoC4.border = true;
NoC3.border = true;
NoC2.border = true;
NoC1.border = true;
Em7.border = true;
Em6.border = true;
Em5.border = true;
Em4.border = true;
Em3.border = true;
Em2.border = true;
Em1.border = true;
Raw5.border = true;
Raw4.border = true;
Raw3.border = true;
Raw2.border = true;
Raw1.border = true;

//--------------------------calculations-------------------------------
calc_btn.addEventListener(MouseEvent.CLICK, Calco);

function Calco(event:MouseEvent):void;
{
iPPP1 = PPP1.text;
iPPP2 = PPP2.text;
iPPP3 = PPP3.text;
iPPP4 = PPP4.text;
iPPP5 = PPP5.text;
iPPP6 = PPP6.text;
iPPP7 = PPP7.text;
iCntbonus = Cntbonus.text;
iRawPrice = RawPrice.text;
iAverSal = AverSal.text;
iTax = Tax.text;
iNoC7 = NoC7.text;
iNoC6 = NoC6.text;
iNoC5 = NoC5.text;
iNoC4 = NoC4.text;
iNoC3 = NoC3.text;
iNoC2 = NoC2.text;
iNoC1 = NoC1.text;
iEm7 = Em7.text;
iEm6 = Em6.text;
iEm5 = Em5.text;
iEm4 = Em4.text;
iEm3 = Em3.text;
iEm2 = Em2.text;
iEm1 = Em1.text;
iRaw5 = Raw5.text;
iRaw4 = Raw4.text;
iRaw3 = Raw3.text;
iRaw2 = Raw2.text;
iRaw1 = Raw1.text;
i1 = (parseInt(iEm1) + parseInt(iNoC1)) * 10 * bonus;
i2 = (parseInt(iEm2) + parseInt(iNoC2)) * 10 * bonus;
i3 = (parseInt(iEm3) + parseInt(iNoC3)) * 10 * bonus;
i4 = (parseInt(iEm4) + parseInt(iNoC4)) * 10 * bonus;
i5 = (parseInt(iEm5) + parseInt(iNoC5)) * 10 * bonus;
i6 = (parseInt(iEm6) + parseInt(iNoC6)) * 10 * bonus;
i7 = (parseInt(iEm7) + parseInt(iNoC7)) * 10 * bonus;

if (parseInt(iCntbonus) == 0) {
    bonus = 1;
} else if (parseInt(iCntbonus) == 1) {
    bonus = 1,2;
} else if (parseInt(iCntbonus) == 2) {
    bonus = 1,4;
} else if (parseInt(iCntbonus) == 3) {
    bonus = 1,6;
} else if (parseInt(iCntbonus) == 4) {
    bonus = 1,8;
} else {
    bonus = 2;
}

// υπολογισμός εσόδων
apotelesma = (Number(iRawPrice)*bonus*parseInt(iRaw1)*35)+(Number(iRawPrice)*bonus*parseInt(iRaw2)*70)+(Number(iRawPrice)*bonus*parseInt(iRaw3)*125)+(Number(iRawPrice)*bonus*parseInt(iRaw4)*175)+(Number(iRawPrice)*bonus*parseInt(iRaw5)*250)

apotelesma = apotelesma + (i1 * Number(iPPP1)) - (i1 * (parseInt(iTax) / 100) + (i2 * Number(iPPP2)) - (i2 * (parseInt(iTax) / 100) + (i3 * Number(iPPP3)) - (i3 * (parseInt(iTax) / 100) + (i4 * Number(iPPP4)) - (i4 * (parseInt(iTax) / 100) + (i5 * Number(iPPP5)) - (i5 * (parseInt(iTax) / 100) + (i6 * Number(iPPP6)) - (i6 * (parseInt(iTax) / 100) + (i7 * Number(iPPP7)) - (i7 * (parseInt(iTax) / 100)
apotelesma.toString()
}

我最后3行有问题......

1 个答案:

答案 0 :(得分:2)

你有一些非常长的计算,并且缺少至少5个关闭的parenetheses。我将第二行粘贴到最后一行(以apotelesma = apotelesma开头的那一行)到文本编辑器中并计算开/关括号的数量。

计算时间太长,不能立即清楚它们应该插入的位置。我会分解计算,以便它们更具可读性。任何维护此代码的人都将从清晰度中受益。

要么将长计算分解为许多较小的计算,要么只是在代码中添加换行符,这样就可以清楚地知道你要做什么了,如下所示:

apotelesma = apotelesma +
    (i1 * Number(iPPP1)) -
    (i1 * (parseInt(iTax) / 100) + // NOTE: you seem to be missing a closing paren here
    (i2 * Number(iPPP2)) -
    (i2 * (parseInt(iTax) / 100) + // and here... (and so on)
    ...