Hello, I am trying to create a really easy program with AS3 where I click a button to randomly select a picture and then I click another button to reveal a number that has been associated with that picture.
I put the pictures in one array and then the numbers in another array
Here is the code I have so far but it doesn’t work, first problem is the pictures do not load on first click, and the numbers don’t match the pictures until some time after clicking continuously…someone please show me where I am going wrong…
var circle1:MovieClip = wanCirc;
var circle2:MovieClip = tooCirc;
var circle3:MovieClip = freeCirc;
var circles:Array = [circle1,circle2,circle3];
var num1:MovieClip = wan;
var num2:MovieClip = too;
var num3:MovieClip = free;
var hold:MovieClip = holder;
var numbers:Array = [num1,num2,num3];
var numHolder:MovieClip = numHold;
butt.addEventListener(MouseEvent.CLICK, onClick);
showButt.addEventListener(MouseEvent.CLICK, onShow);
function onClick(event:MouseEvent):void {
hold.x = 50;
hold.y = 50;
for(var i = 0; i<circles.length; i++){
hold = circles[Math.floor(Math.random()*circles.length)];
addChild(hold);
}
trace("click");
}
function onShow(event:MouseEvent):void {
numHolder.x = 200;
numHolder.y = 200;
for (var i = 0; i<numbers.length; i++){
if(hold == circle1){
numHolder = num1;
}
else if(hold == circle2){
numHolder = num2;
}
else if(hold == circle3){
numHolder = num3;
}
addChild(numHolder);
}
}