PDA

View Full Version : newbie random MC help



mogi
April 29th, 2003, 09:39 AM
i'm trying to create some buttons as MCs that will load random imageMCs on release or rollover

i think i am supposed to use math random in some form with MCs but i have no idea how to execute the script for that

any ideas and advice would be appreciated

thanks in advance

mogi

Flashmatazz
April 29th, 2003, 10:57 AM
You could do it like this:
- name the imageMC's: imageMC1, imageMC2, imageMC3 etc.
- on the button place something like this:


on(release){
// if there are 3 imageMC's
myTarget = Math.round(Math.random(2)+1);
_root["imageMC"+myTarget].play();
}


Math.random(2) gives you a random value between 0 and 2
+1 makes this a number between 1 and 3.
Math.round() rounds this value to the nearest integer, e.g. 2.132 will become 2

Note that in this case if myTarget would equal 2, then _root["imageMC"+myTarget].play() would tell imageMC2 to start playing.

Hope I've explained everything correctly =)