Thanks to marz for suggesting that I use splice in my array yesterday, I took your advise on board and my prototype nearly works, and for the life of me I cant understand why it doesn’t remove all the elements from the array, It removes 1 and 2 fine but doesn’t remove 3 and 4, I don’t know if anyone could explain to me why this doesn’t work. Ive included the entire code below; if you could help me out I’d be chuffed, cheers.
_root.Work._visible = false;
_root.one._visible = false;
_root.two._visible = false;
_root.three._visible = false;
_root.four._visible = false;
myfirstarray = new Array();
myfirstarray[0]=_root.one,
myfirstarray[1]=_root.two,
myfirstarray[2]=_root.three,
myfirstarray[3]=_root.four;
//generate random number
_root.button.onPress = function() {
randomnumber = Math.round(Math.random()*(myfirstarray.length-1));
selectednumber = myfirstarray[randomnumber];
if (selectednumber == _root.one) {
myfirstarray.splice(0, 1);
trace(myfirstarray);
_root.one._visible = true;
_root.two._visible = false;
_root.three._visible = false;
_root.four._visible = false;
if (myfirstarray.length<=0) {
Work._visible = true;
}
}
if (selectednumber == _root.two) {
myfirstarray.splice(1, 1);
trace(myfirstarray);
_root.two._visible = true;
_root.one._visible = false;
_root.three._visible = false;
_root.four._visible = false;
if (myfirstarray.length<=0) {
Work._visible = true;
}
}
if (selectednumber == _root.three) {
myfirstarray.splice(2, 1);
trace(myfirstarray);
_root.two._visible = false;
_root.one._visible = false;
_root.three._visible = true;
_root.four._visible = false;
if (myfirstarray.length<=0) {
Work._visible = true;
}
}
if (selectednumber == _root.four) {
myfirstarray.splice(3, 1);
trace(myfirstarray);
_root.two._visible = false;
_root.one._visible = false;
_root.three._visible = false;
_root.four._visible = true;
if (myfirstarray.length<=0) {
Work._visible = true;
}
}
_root.output.text = selectednumber.text;
};
_root.button.onRelease = function() {
};