flashcards activity problem: matching image and answer arrays
Hi there, I hope someone can help...
I'm building a Flashcard activity:
click button -> show random image (from dynamic array);
click button -> show answer (from another array) that matches image.
I have the random images part sorted; but having problems identifying the current image shown so that its index can be matched against the answer array's index.
Here are relevant code bits:
//add image holder
var holder:picHolder = new picHolder();
addChild(holder);
//set up image array and random variable
var allPics:Array = [];
for (var i:int = 1; i<=numPics; i++)
{
var thePic:Class = getDefinitionByName("pic" + i) as Class;
var myPic:MovieClip = new thePic();
myPic.name = "pic" + i;
allPics.push(myPic);
}
var nextCard = Math.round(Math.random() * allPics.length - 1);
//next card button and random image function: toggle answer & button visibles, call random function
nextFC.addEventListener(MouseEvent.CLICK, swapButtons);
function swapButtons(event:MouseEvent):void
{
theAnswer.visible = false;
nextFC.visible = false;
checkMe.visible = true;
placeCard(event);
}
function placeCard(event:MouseEvent):void
{
nextCard = Math.round(Math.random() * allPics.length - 1);
nextCard = (nextCard > -1) ? nextCard : 0;
holder.addChild(allPics[nextCard]);
}
var allAnswers:Array = ["Flower","Landscape","Shrub","Jellyfish"];
//call answer function
checkMe.addEventListener(MouseEvent.CLICK, showAnswer);
//answer function: hide check button, show answer and next button;
function showAnswer(event:MouseEvent):void
{
checkMe.visible = false;
holder.removeChild(allPics[nextCard]);
theAnswer.visible = true;
//test
theAnswer.text = "description here - need match answer in allAnswers array with random image from allPics array.";
//end test
nextFC.visible = true;
}
Many thanks for any help anyone can give to solve this
.
ps:
If you like I can paste in whole code in case it makes it easier to see what I'm trying to do (acn't see a way to upload FLA to this forum).
