Thank you for your reply, but it won't work.
I got this error.
TypeError: Error #1034: Error forced conversion
I guess it comes from this line
var mcA:Array = a[Math.floor(Math.random()*a.length)];
If you can please tell me how to use this code.
This is the fla file I am working at.
http://www.dotup.org/uploda/www.dotup.org3939431.fla.
i used mcA for an array reference and you used mcA for a movieclip reference which caused that error:
// an array of arrays. each element of a is allowable sequence of movieclips
var a:Array=[[mcA,mcB],[mcA,mcB,mcB],[mcC,mcD,mcE],[mcC,mcD,mcD,mcE],[mcC,mcD,mcD,mcD,mcE]];
// mc_A is a randomly chosen element of a. ie, one of the allowable sequences of movieclips
var mc_A:Array=a[ Math.floor(Math.random()*a.length)]
// the movieclips in mcA will be played from the first until the last
var index:int=0;
var mc:MovieClip;
// playF starts the next movieclip in mcA playing (and as i'm typing this i realize i failed to add an mc.play() in playF)
playF();
function playF():void {
mc=mc_A[index];
// start it playing
mc.gotoAndPlay(2);
// if mc needs to be added to the stage or needs to be made visible etc, this is the place to do that
// add a loop to check when it finishes playing so we can start the next movieclip in mcA
mc.addEventListener(Event.ENTER_FRAME,enterframeF);
}
function enterframeF(e:Event):void {
// check if mc has completed play
if (mc.currentFrame==mc.totalFrames) {
// if so, remove the listener
mc.removeEventListener(Event.ENTER_FRAME,enterframeF);
// if mc no longer needs to be on stage or no longer needs to be visible etc, this is the place to do that
// increment the index anticipating starting the next movieclip in mcA
index++;
// if there's another mcA element left to play, play it
if (index<mc_A.length) {
playF();
} else {
// all done. do something?
}
}
}