您應該:
//document class
package
{
import flash.display.Sprite;
import flash.events.Event;
public class DocumentClass extends Sprite
{
public static var GAME;
public function DocumentClass() {
addEventListener(Event.ADDED_TO_STAGE, init);
}
private function init(e:Event){
removeEventListener(Event.ADDED_TO_STAGE, init);
GAME = new Game();
}
}
}
//Game class
package
{
import flash.display.Sprite;
import flash.events.Event;
public class Game extends Sprite
{
public var score:int;
public function Game() {
addEventListener(Event.ADDED_TO_STAGE, init);
}
private function init(e:Event){
removeEventListener(Event.ADDED_TO_STAGE, init);
//some functions/listeners & variable settings.
score = 0;
}
private function someFunction() {
stage.addChild(new HighscoreTable(score));//passing score to the highscore table...
}
}
}
靜態類(只包含靜態變量&無構造函數)往往沒用..嘗試將它與其他「招數」結合起來。
爲什麼要創建Class C的實例作爲Score?它是否只包含一個變量?你應該在遊戲中製作一個公共變量來跟蹤分數。 – Zhafur 2012-07-29 16:32:28
你是說我應該在Main類中創建一個公共類? – m4g4bu 2012-07-29 16:48:47