[SIZE=2][FONT=arial]So basically, I’m trying to create a program that is going to take numbers from the user, and then use a pre-programmed function that generates random numbers, and I will compare the two.
So I’ve created 3 frames:
- A title screen.
2)A screen that takes the users numbers and then when they press a “Go!” button to move to the next page, it casts them to an array. - A page where a button is pressed that will generate and show the random numbers, cast them to an array, and compare the two arrays.
This was all working fine until I tried to use for loops to program the comparison. Now, it’s throwing null object errors left, right and center. It’s like it’s suddenly stopped carrying over the array from frame 2, for no reason.
I don’t really want to do it all on one frame because it’d be very messy, and I’m not really sure why it’s suddenly stopped working.
Here’s my code anyway:
[/FONT][/SIZE]//importLotteryDraw
import uk.ac.uwe.multimedia.lottery.LotteryDraw;
//show users chosen numbers
userNumberShow1.text = mainArray[0];
userNumberShow2.text = mainArray[1];
userNumberShow3.text = mainArray[2];
userNumberShow4.text = mainArray[3];
userNumberShow5.text = mainArray[4];
userNumberShow6.text = mainArray[5];
//get generated numbers from program
var drawnNumbers:LotteryDraw = new LotteryDraw();
drawnNumbers.chooseNumbers();
//assign numbers to array;
var drawnArray:Array = new Array();
drawnArray[0] = drawnNumbers.getNumber(0);
drawnArray[1] = drawnNumbers.getNumber(1);
drawnArray[2] = drawnNumbers.getNumber(2);
drawnArray[3] = drawnNumbers.getNumber(3);
drawnArray[4] = drawnNumbers.getNumber(4);
drawnArray[5] = drawnNumbers.getNumber(5);
drawnArray[6] = drawnNumbers.getNumber(6);
mainArray[0] = userNumber1.text;
mainArray[1] = userNumber2.text;
mainArray[2] = userNumber3.text;
mainArray[3] = userNumber4.text;
mainArray[4] = userNumber5.text;
mainArray[5] = userNumber6.text;
programNumber1.text = drawnArray[0];
programNumber2.text = drawnArray[1];
programNumber3.text = drawnArray[2];
programNumber4.text = drawnArray[3];
programNumber5.text = drawnArray[4];
programNumber6.text = drawnArray[5];
programBonusNumber.text = drawnArray[6];
//show drawn numbers to user one by one.
GoButton.addEventListener(MouseEvent.CLICK, compareNumbers);
function compareNumbers(event:MouseEvent)
{
//compare numbers
var i:int;
var j:int;
var match:int;
var bonusMatch:Boolean;
for (i = 0; i <mainArray.length; i++)
{
if (mainArray* == drawnArray[6])
{
bonusMatch = true;
trace("BONUS YAY");
}
for (j = 0; j<drawnArray.length; j++)
{
if (mainArray* == drawnArray[j])
{
match++;
}
}
}
trace(match);
}
mainArray was cast in the frame beforehand.
I’m stressing about this more than necessary. GAH.