我在动作脚本3中制作的游戏中存在一些问题。我使用FlashDevelop读过的每个教程中的知识来制作它。我在这段代码中遇到了一些错误,但是,这阻止了我编译。这里是仅有的两个AS文件,它迄今:FlashDevelop中的奇怪问题
Main.as
package
{
import flash.display.Sprite;
import flash.events.Event;
import flash.events.TimerEvent;
import flash.utils.Timer;
import flash.events.KeyboardEvent;
import flash.ui.Keyboard;
public class Main extends Sprite
{
public var gameTimer:Timer
public var LeftisPressed:Boolean;
public var RightisPressed:Boolean;
public var jumper = new Jumper;
public function Main()
{
gameTimer = new Timer(40)
gameTimer.addEventListener(TimerEvent.TIMER, onTick);
RightisPressed = false;
LeftisPressed = false;
addEventListener(Event.ADDED_TO_STAGE, OnAddToStage());
jumper = new Jumper();
addChild(jumper);
}
public function OnAddtoStage() :void
{
stage.addEventListener(KeyboardEvent.KEY_DOWN, onKeyPress);
stage.addEventListener(KeyboardEvent.KEY_UP, onKeyRelease);
}
public function onTick (timerEvent: TimerEvent) :void
{
if (LeftisPressed)
{
jumper.Left();
}
if (RightisPressed)
{
jumper.Right();
}
}
public function onKeyPress (keyboardEvent: KeyboardEvent) :void
{
if (KeyboardEvent.keyCode == Keyboard.LEFT)
{
LeftisPressed = true;
}
if (KeyboardEvent.keyCode == Keyboard.RIGHT)
{
RightisPressed = true;
}
}
public function onKeyRelease(keyboardEvent: KeyboardEvent) :void
{
if (KeyboardEvent.keyCode == Keyboard.LEFT)
{
LeftisPressed = false;
}
if (KeyboardEvent.keyCode == Keyboard.RIGHT)
{
LeftisPressed = false;
}
}
}
}
Jumper.as
package
{
import flash.display.Sprite;
import flash.events.Event;
import flash.events.TimerEvent;
import flash.utils.Timer;
import flash.events.KeyboardEvent;
import flash.ui.Keyboard;
/**
* ...
* @author Timothy Bumpus
*/
public class Jumper extends Sprite
{
public function Jumper()
{
var square:Sprite = new Sprite();
addChild(square);
square.graphics.lineStyle(3,0x00ff00);
square.graphics.beginFill(0x0000FF);
square.graphics.drawRect(0,0,100,100);
square.graphics.endFill();
square.x = 250
square.y = 350
}
public function Left()
{
x = x - 3
}
public function Right()
{
x = x + 3
}
}
}
(如果它关系到你,这就是所谓的跳线因为我最终会跳跃。)
这个想法是让一个精灵左右移动到相应的键上。但是当我尝试和调试它时,它给了我5个错误,“col:44错误:调用一个可能未定义的方法OnAddToStage。”和“col:22错误:通过带有静态类型Class的引用访问可能未定义的属性keyCode”。每次我提到keyCode。在搜索互联网之后,我唯一的结论是它与Flash SDK使用的Flex SDK有关,但我无法找到关于该上下文中的错误的任何具体帮助。
我不能是唯一有这个问题的人。有任何想法吗?
哦,男人......回头看,这很明显。我想我倾向于过度考虑事情...找不到其他任何帮助我得出结论的地方,非常感谢,你们两个! – Puzzlem00n
我真的应该道歉,在我面前时,我一直在寻找一个更大的问题。 – Puzzlem00n
@user:不用担心。下次你会更仔细地阅读编译错误;-) – Cameron