Hey
I’m pretty new to action script. I’m trying to create a simple user name and password screen which will link to a menu and in the menu will have a choice of three games to play.
frame 1 is the logon screen. Frame 2 the menu. Frames 3,4 and 5 the games.
I managed to create the logon screen, the menu and the first game but the error below appears when clicking on the button to go to the first game in frame 3
Cannot access a property or method of a null object reference.
at logon_Scene1_fla::MainTimeline/init()
at logon_Scene1_fla::MainTimeline/frame3()
at flash.display::MovieClip/gotoAndPlay()
at logon_Scene1_fla::MainTimeline/gotoFrame3()
Here is the code for the logon screen which works fine:
stop();
enterBtn.addEventListener(MouseEvent.CLICK, loginFunction);
function loginFunction(e:MouseEvent):void{
if(UserName.text == “dan” && Password.text == “dan”){
gotoAndStop(2);
}else{
var fmt:TextFormat = new TextFormat();
fmt.color = 0xff0000;
Messagetxt.text = “Incorrect username or password”;
Messagetxt.setTextFormat(fmt);
}
}
Code for menu screen in frame 2.
stop();
LogOutBtn.addEventListener(MouseEvent.CLICK, gotoFrame1);
function gotoFrame1(e:MouseEvent):void{
gotoAndStop(1);
}
Numbers_Btn.addEventListener(MouseEvent.CLICK, gotoFrame3);
function gotoFrame3(e:MouseEvent):void{
gotoAndPlay(3);
}
Spinners_Btn.addEventListener(MouseEvent.CLICK, gotoFrame4);
function gotoFrame4(e:MouseEvent):void{
gotoAndStop(4);
}
Bubbles_Btn.addEventListener(MouseEvent.CLICK, gotoFrame5);
function gotoFrame5(e:MouseEvent):void{
gotoAndStop(5);
}
and the code for the first game which is just a simple number guessing game in frame 3.
stop();
var beginMessage:String;
var randomNumber:uint;
var my_guess:uint;
function init():void {
play_again_btn.enabled =false;
guess_btn.enabled = true;
beginMessage=“Choose a number between 1 - 100.”;
message_txt.text=beginMessage;
message_txt.restrict=“0-9”;
input_txt.text="";
randomNumber = Math.floor(Math.random() * 100 + 1);
guess_btn.addEventListener(MouseEvent.CLICK, yourGuess);
}
function yourGuess(event:MouseEvent):void {
my_guess=uint(input_txt.text);
if (my_guess > randomNumber) {
message_txt.text = “Your guess, " + my_guess + " is too high.”;
}
else if (my_guess < randomNumber) {
message_txt.text = “Your guess, " + my_guess + " is too low.”;
}
else{
message_txt.text = "Well done, the number is " + randomNumber + “.”;
winGame();
}
}
function winGame():void{
guess_btn.enabled = false;
play_again_btn.enabled = true;
guess_btn.removeEventListener(MouseEvent.CLICK, yourGuess);
play_again_btn.addEventListener(MouseEvent.CLICK, guessAgain);
}
function guessAgain(event:MouseEvent):void{
init();
}
init();
I know the problem exist the in init function. If I run the game in a new program, just 1 frame, it works fine, but with mutiple frames and scripts, the error. I’ve double checked all buttons and text boxes and everything is in place and named correctly.
an anybody help please :hurt: