PlayState
当我在进入菜单状态后尝试切换回我时遇到问题。当我在菜单状态上单击“返回”时,当游戏尝试添加时,我收到一条错误消息,指出“[Fault] 异常,信息 = TypeError:错误 #1009:无法访问空对象引用的属性或方法”离开我的菜单状态后 PlayState 中的按钮。这是用于测试的 PlayState 代码片段:
public class PlayState extends FlxState
{
override public function create():void
{
// ...
add(new FlxButton(0, 0, "test"));
}
}
这是我的菜单状态:
import org.flixel.*;
public class stand_menu extends FlxState
{
public var ps:PlayState;
public function stand_menu(PS:PlayState)
{
ps = PS;
}
override public function create():void
{
FlxG.bgColor = 0xFFFFFFFF;
var bttn:FlxButton = new FlxButton(10, 10, "add cash",add_cash);
this.add(bttn);
var bttn2:FlxButton = new FlxButton(10, 30, "go back",go_back);
this.add(bttn2);
}
public function add_cash():void
{
ps.cash += 10;
}
public function go_back():void
{
FlxG.switchState(ps);
}
}