好的,所以我尝试了一些我见过的类似问题的解决方案但是却无法解决这个问题。这是代码....
package {
import flash.events.*;
import flash.display.MovieClip;
import Game.C;
public class GameController extends MovieClip {
public function startGame() {
stage.addEventListener(Event.ENTER_FRAME, gameLoop);
}
function gameLoop(evt: Event): void {
//Handle User Input
//Handle Game Logic
cpuSquare.x += C.squareSpeed;
cpuSquare.y += C.squareSpeed;
//Handle Display
}
}
}
然后从游戏包......
package Game
{
public class C
{
public var squareSpeed:int = 3;
}
}
答案 0 :(得分:2)
您正在尝试引用静态属性。静态属性是属于该类的属性,而不是该类的实例。
要解决此问题,您必须使squareSpeed成为静态属性。
public static var squareSpeed:int = 3
否则你将不得不创建一个C的实例并使用它,但我不认为这是你在这里尝试做的。
以下是你如何做以防万一。
var cInstance:C = new C();
cpuSquare.x += cInstance.squareSpeed;
cpuSquare.y += cInstance.squareSpeed;