Hello
I am creating a quiz in which the user matches an object (movie clip), to a sound clip that is played. The sounds are stored in an array and a random one is chosen. Then 4 random movie clips are created dynamically which hold the object image. I need a way to link the sound clip to the movie clips to check if the correct one was clicked. Here is the code so far:
var randSound = Math.round(Math.random()*1); // Rand no 0-4
var sounds:Array = [cat, doorCreek]; // Sound array
var soundClip:Sound = new sounds[randSound]; // Create random sound
sound_btn.addEventListener(MouseEvent.CLICK, playSound); // Re-play sound button
function playSound(e:MouseEvent) { soundClip.play(); }
var clips:Array =[cat, door, wind, water]; // Movie clip array (will be longer)
// Add objects to stage
for(var i=0; i<4; i++)
{
var rand = Math.round(Math.random()*4); // 4 clips as answer options
var myRandClip:MovieClip=new clips[rand]; // Create random movieclip
// Create listener for the movieclip
myRandClip.addEventListener(MouseEvent.CLICK, getIndex);
function getIndex(e:MouseEvent)
{
trace(rand);
}
this.addChild(myRandClip);
}
Of course at the moment this function to get the index of the movie clip just gets the last rand number generated. I need a way to embed some sort of id into the generated movie clip. I can then simply test if it is the same as the sound clips index for example. I'll then be doing the same for each question (10 in total)
Hope that is clear and someone can help out. Many Thanks