2015-11-03 40 views
0

我正在使用基本運動引擎上的ActionScript3.0。當我嘗試測試我的代碼,我得到這個錯誤:語法錯誤:期待結束之前的rightparen

MovementClass.as, Line 44, Column 22 1084: Syntax error: expecting rightparen before colon. 

我得到這個爲線44,52,60,和下面的代碼68;這些行是heroGoing < 方向>(e:TimerEvent);

package { 
import flash.display.*; 
import flash.display.MovieClip; 
import flash.events.Event; 
import flash.events.KeyboardEvent; 
import flash.ui.Keyboard; 
import flash.utils.Timer; 
import flash.events.TimerEvent; 
import flash.events.TimerEvent; 


public class MovementClass extends MovieClip { 
    var reference:Reference = new Reference(); 
    var hero:Hero = new Hero(); 
    var enemy:Enemy = new Enemy(); 
    var wall:Wall = new Wall(); 

    //Timer 
    var moveTimer:Timer = new Timer(25, 10) 

    //Booleans 
    var movingHeroRight:Boolean = false; 
    var movingHeroLeft:Boolean = false; 
    var movingHeroUp:Boolean = false; 
    var movingHeroDown:Boolean = false; 

    public function MovementClass() { 
     hero.x = stage.stageWidth * .5; 
     hero.y = stage.stageHeight * .5; 
     addChild(hero); 
     startEngine(); 
    } 

    public function startEngine():void { 
     stage.addEventListener(KeyboardEvent.KEY_DOWN, movementHandler); 
     stage.addEventListener(KeyboardEvent.KEY_UP, stopHandler); 
    } 

    public function movementHandler(keyDown:KeyboardEvent):void { 
     if (keyDown.keyCode == 39) { 
      if (movingHeroLeft == true, movingHeroUp == true, movingHeroDown == true) { 
       return; 
      } else { 
       heroGoingRight(e:TimerEvent); 
       movingHeroRight = true; 
       moveTimer.start; 
      } 
     } else if (keyDown.keyCode == 37) { 
      if (movingHeroRight == true, movingHeroUp == true, movingHeroDown == true) { 
       return; 
      } else { 
       heroGoingLeft(e:TimerEvent); 
       movingHeroLeft = true; 
       moveTimer.start; 
      } 
     } else if (keyDown.keyCode == 38) { 
      if (movingHeroLeft == true, movingHeroRight == true, movingHeroDown == true) { 
       return; 
      } else { 
       heroGoingUp(e:TimerEvent); 
       movingHeroUp = true; 
       moveTimer.start; 
      } 
     } else if (keyDown.keyCode == 40) { 
      if (movingHeroLeft == true, movingHeroUp == true, movingHeroRight == true) { 
       return; 
      } else { 
       heroGoingDown(e:TimerEvent); 
       movingHeroDown = true; 
       moveTimer.start; 
      } 
     } 
     //moveTimer.start(); 
    } 

    function heroGoingUp(eUp:TimerEvent):void { 
     if (movingHeroUp == true) { 
      reference.y += 5; 
     } 
    } 

    function heroGoingDown(eDown:TimerEvent):void { 
     if (movingHeroDown == true) { 
      reference.y -= 5; 
     } 
    } 

    function heroGoingLeft(eLeft:TimerEvent):void { 
     if (movingHeroLeft == true) { 
      reference.x += 5; 
     } 
    } 

    function heroGoingRight(eRight:TimerEvent):void { 
     if (movingHeroRight == true) { 
      reference.x -= 5; 
     } 
    } 

    public function stopHandler(keyUp:KeyboardEvent):void { 
     if (movingHeroRight == true) { 
      movingHeroRight = false; 
     } else if (movingHeroLeft == true) { 
      movingHeroLeft = false; 
     } else if (movingHeroUp == true) { 
      movingHeroUp = false; 
     } else if (movingHeroDown == true) { 
      movingHeroDown = false; 
     } 
    } 
} 
} 

我在做什麼錯?

+0

如果您將行號添加到代碼中,將會很好。 – agabrys

+1

更好的是,使用您正在使用的語言標記您的帖子。如果發佈版本很重要(例如python2,而不是python),那就要特別注意。 – Prune

+0

改進的代碼和消息格式。做了輕微的措辭更新。添加C++標籤 – Prune

回答

1

問題是與第一heroMoving電話:

  heroGoingRight(e:TimerEvent); 

編譯器認爲你想在原地來聲明一個變量。聲明e:TimerEvent適當,之前你使用它,你應該沒問題。

相關問題