views:

710

answers:

1

Hi All.

I'm making a flash quiz which will have a series of questions. Each question will have a button which will read the question out. As well as 4 buttons (probably MC's), that the user will click to answer. Each question is a different sound clip and a different set of answers.

Problem is, I need to do it dynamically so I can pick a random sound clip from the library, and 4 random buttons. One of which will be the correct answer. So far I have manged to work out how to create dynamic instances of an object and display it in a random location:

for(var i=0; i<5; i++)
{
    var appleMovie:appleMc    = new appleMc();       
    appleMovie.x = +Math.random()*50;
    appleMovie.y = +Math.random()*50;

    this.addChild(appleMovie);
}

I can grab random values from an array of movieClip names like:

var fruit = new Array("apple", "pear", "grape", "lemon");
var randomValue:Number  =  Math.random()*1;
fruit[randomValue];

But this doesn't seem to help when wanting different objects dynamically. Am I going about this the correct way? Should the answer buttons be movie clips that generate their own random graphic as the image? I'm a bit lost on this one. Any help would be really appreacited.

+2  A: 

Hi,

Like your array of name, new Array("apple", "pear", "grape", "lemon"); you can create an Array filled with Class objects.

var randMcs:Array=[AppleMc,LemonMc,TestMc];
var randomValue:Number  =  Math.random()*1;
var randMc:Class = randMcs[randomValue] as Class;
var myRandMc:MovieClip=new randMc() as MovieClip;

Hope it will help you !

OXMO456
Thats really useful thanks. Been trying to figure that one out all day. Now just gotta figure out how to score it :/
whamo