我在動作腳本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