您应该:
//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