Monday, November 25, 2013

Error #1009: Cannot access a property or method of a null object reference. -AS3 [android help]


Error #1009: Cannot access a property or method of a null object reference. -AS3



i got this error:



TypeError: Error #1009: Cannot access a property or method of a null object reference.
at TriviaGameDeluxe/saveScore()[TriviaGameDeluxe::frame102:19]


This is my code:



//**//
playAgainbutton.addEventListener(MouseEvent.CLICK,saveScore);


function saveScore(event:MouseEvent) { // Save the score


if (savedSN == null) { // Check if a game save is created. If it is not, create one
trace("New game save created");
savedSN = { // Set the varible 'savedSN'
name1:"-",
name2:"-",
name3:"-",
name4:"-",

score1:"-",
score2:"-",
score3:"-",
score4:"-"};
soSavedScNa.data.nameScore = savedSN; // Set the data in the save file to the
savedSN variable
soSavedScNa.flush(); // Overwrite existing save file

}

//**// Save the score
if ((gameScore > savedSN.score1 || savedSN.score1 == "-") &&
gameScore != 0) {
trace("Score 1");
savedSN = { // Set the date the savedSN varible will have
name1:PName.text,
name2:savedSN.name1,
name3:savedSN.name2,
name4:savedSN.name3,
score1:gameScore,
score2:savedSN.score1,
score3:savedSN.score2,
score4:savedSN.score3};
soSavedScNa.data.nameScore = savedSN; // Set the data in
the save file to the savedSN variable
soSavedScNa.flush(); // Overwrite existing save file
playAgainbutton.removeEventListener(MouseEvent.MOUSE_UP,
saveScore);
cleanUp();
gotoAndStop(1); // Go to the start menu
} else if ((gameScore > savedSN.score2 || savedSN.score2 == "-") &&
gameScore != 0) {
trace("Score 2");
savedSN = { // Set the date the savedSN varible will have
name1:savedSN.name1,
name2:PName.text,
name3:savedSN.name2,
name4:savedSN.name3,
score1:savedSN.score1,
score2:gameScore,
score3:savedSN.score2,
score4:savedSN.score3};
soSavedScNa.data.nameScore = savedSN; // Set the data in
the save file to the savedSN variable
soSavedScNa.flush(); // Overwrite existing save file
playAgainbutton.removeEventListener(MouseEvent.MOUSE_UP,
saveScore);
cleanUp();
gotoAndStop(1);
// Go to the start menu
} else if ((gameScore > savedSN.score3 || savedSN.score3 == "-") &&
gameScore != 0) {
trace("Score 3");
savedSN = { // Set the date the savedSN varible will have
name1:savedSN.name1,
name2:savedSN.name2,
name3:PName.text,
name4:savedSN.name3,
score1:savedSN.score1,
score2:savedSN.score2,
score3:gameScore,
score4:savedSN.score3};
soSavedScNa.data.nameScore = savedSN; // Set the data in
the save file to the savedSN variable
soSavedScNa.flush(); // Overwrite existing save file
playAgainbutton.removeEventListener(MouseEvent.MOUSE_UP,
saveScore);

cleanUp();
gotoAndStop(1); // Go to the start menu
} else if ((gameScore > savedSN.score4 || savedSN.score4 == "-") &&
gameScore != 0) {
trace("Score 4");
savedSN = { // Set the date the savedSN varible will have
name1:savedSN.name1,
name2:savedSN.name2,
name3:savedSN.name3,
name4:PName.text,
score1:savedSN.score1,
score2:savedSN.score2,
score3:savedSN.score3,
score4:gameScore};
soSavedScNa.data.nameScore = savedSN; // Set the data in
the save file to the savedSN variable
soSavedScNa.flush(); // Overwrite existing save file
playAgainbutton.removeEventListener(MouseEvent.MOUSE_UP,
saveScore);
cleanUp();
gotoAndStop(1); // Go to the start menu
}
}


I cannot find where the error is.. Hope anybody can help. Thanks.



Read more

stackoverflow.comm



No comments:

Post a Comment

Google Voice on T-Mobile? [General]

Google Voice on T-Mobile? So I recently switched from a GNex on Verizon to a Moto X DE on T-Mobile. I had always used Google Voice for my v...