Playing a random movie clip using a simple timer - this should be easy!
This should be a REALLY simple problem to solve - but I'm stuck!
I have 5 movie clips on the stage called ball_1 through ball_5.
I'm trying to get them to play in a random order using a timer and the Math.random() method.
My problem comes when I try to concatenate a string or integer with a movieClip name.
I really hope someone can let me know how to do this. Here's my code:
---------------------------------------------------------------------------
var whichBall:int;
var myDelay:int = 2000;
var myCount:int = 20;
var myTimer:Timer = new Timer(myDelay, myCount);
myTimer.addEventListener(TimerEvent.TIMER, game);
function game(evt:Event):void
{
whichBall = Math.ceil((Math.random()*6));
ball_+whichOne.play();//this is the line that's giving me the error!
}
myTimer.start();
---------------------------------------------------------------------------
The error message says that I cannot access an undefined property ball_
I've tried defining "ball_" as a string etc. but I don't think it's possible to concatenate strings with MovieClip names in AS3 - if any of you have Gary's old book "Flash MX ActionScript for fun & Games" he uses this technique in the Whack-a-Fox game - to get the Fox MovieClips to randomly pop up.
Any ideas????????
Copyright Gary Rosenzweig
