使用 flash as3 创建菜单时遇到问题。你们能帮我怎么办...?像这样 :
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at DocumentClass/menuScreen()
at DocumentClass/mouseBack()
如何正确的代码来修复下面的代码:
package {
import flash.display.MovieClip;
import flash.events.Event;
import flash.display.SimpleButton;
import flash.events.MouseEvent;
import flash.system.fscommand;
import flash.display.StageDisplayState;
public class DocumentClass extends MovieClip {
public var backbutton:BackButton = new BackButton();
public function DocumentClass() {
menuScreen();
stage.addEventListener(Event.ENTER_FRAME, masukGame);
}
public function masukGame(e:Event):void{
stage.displayState = StageDisplayState.FULL_SCREEN;
}
public function menuScreen():void{
game.menuscreen.mb.addEventListener(MouseEvent.MOUSE_DOWN, mouseClick1);
game.menuscreen.pb.addEventListener(MouseEvent.MOUSE_DOWN, mouseClick2);
game.menuscreen.mlb.addEventListener(MouseEvent.MOUSE_DOWN, mouseClick3);
game.menuscreen.kb.addEventListener(MouseEvent.MOUSE_DOWN, mouseClick4);
}
public function backMenu():void{
backbutton.buttonMode = true;
backbutton.addEventListener(MouseEvent.MOUSE_DOWN, mouseBack);
backbutton.x = 450;
backbutton.y = 400;
// Dan akhirnya letakan button ke stage;
addChild(backbutton);
backbutton.visible=true;
}
public function mouseClick1(event:MouseEvent):void {
game.gotoAndStop("MainGame");
backMenu();
}
public function mouseClick2(event:MouseEvent):void {
game.gotoAndStop("Petunjuk");
backMenu();
}
public function mouseClick3(event:MouseEvent):void {
game.gotoAndStop("Malaria");
backMenu();
}
public function mouseClick4(event:MouseEvent):void {
game.gotoAndStop("Keluar");
backMenu();
}
public function mouseBack(event:MouseEvent):void {
menuScreen();
}
}
}
这是我的文件,在这里下载:https ://www.dropbox.com/s/jo7bcwnlfj7qjnh/My%20Game.rar
请帮助我,谢谢各位...