我在基本的移动引擎上使用ActionScript3.0。当我尝试测试我的代码时,我收到此错误:
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 :(得分:1)
问题在于第一次 heroMoving 调用:
heroGoingRight(e:TimerEvent);
编译器认为您正在尝试声明一个变量 in situ 。适当地声明 e:TimerEvent ,之前使用它,你应该没问题。