2012-08-04 61 views
0

我正在嘗試製作遊戲的工具... 按下按鈕會在計算後給出一些結果。該代碼尚未完成,但它不必提供錯誤。下面是代碼:語法錯誤1084無論我做什麼

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

AAAAH!使用數組!在'for'循環中,使用getChildByName(「Raw」+ i)'並將數據作爲數字分配到數組項中,因此不需要'parseInt()';你也將擺脫所有的'字符串'變量。並且計算也應該變成'for'循環。你真的需要參加計算機科學入門課程或類似的在線課程。 – iND 2012-08-04 20:36:37

回答

2

你有一些很長的計算,並且缺少ATLEAST 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) 
    ... 
+0

感謝的人......現在我有新的問題...... 場景1,圖層「操作」,第1幀,114線\t 1126:功能不具有體。 看起來功能有問題... – 2012-08-04 20:43:18

+0

這是分號字符';'在函數聲明結束時,應該刪除它:'function Calco(event:MouseEvent):void;' – 2012-08-04 20:48:25

+0

Thanks Thanks ! 現在一切正常! – 2012-08-04 20:50:46