Select a random movieclip form an array of movieclips

Hi, iv been trying to find out how i can attach a random movieclip form an array of movieclips.

Iv got this so far, i have searched the forum etc for help and i am pretty stuck.

var logo_arr:Array = new Array("logo01", "logo02", "logo03", "logo04", "logo05", "logo06", "logo07", "logo08", "logo09", "logo010", "logo011");
var randomLogo:Number = logo_arr[Math.floor(Math.random()*11)];
var dynamiclogo_mc = this.attachMovie("randomLogo", "randomLogo", 3);
dynamiclogo_mc._x = Stage.width/2 - 180 ;
dynamiclogo_mc._y = Stage.height/2 - 420;

All my movieclips are in the library and have the linkage for actionscipt enabled.

I cant see what it is im missing?

Any help is much apreciated

Thanks, SamI:-)

erm because you are attaching the same MC?

attachMovie([“logo”+randomLogo],randomlogo,different depth )

sort of

Sorry, im a newb at this and do not understand your reply???


I’ve improved the code a little, you need to give each MC a different name and a different depth

noob yourself :stuck_out_tongue:

var logo_arr:Array = new Array(“logo01”, “logo02”, “logo03”, “logo04”, “logo05”, “logo06”, “logo07”, “logo08”, “logo09”, “logo010”, “logo011”);

var randomLogo = logo_arr[Math.floor(Math.random()*11)];

var dynamiclogo_mc = this.attachMovie(randomLogo, randomLogo, 3*something);

dynamiclogo_mc._x = Stage.width/2 - 180 ;
dynamiclogo_mc._y = Stage.height/2 - 420;

Thanks verymuch,

iv been looking at it so long it just didnt notice the



NEVER datatype lol

well maybe once you’ve finished

yikes, that’s unfortunate. there’s nothing wrong with datatyping–as long as you pick the correct type (which would be movieclip, not number, in this case).

gotta go with adobe on this one:

Because data type mismatches trigger compiler errors, strict data typing helps you find bugs in your code at compile time and prevents you from assigning the wrong type of data to an existing variable. During authoring, strict data typing activates code hinting in the ActionScript editor (but you should still use instance name suffixes for visual elements).

Using strict data typing helps ensure that you don’t inadvertently assign an incorrect type of value to a variable. Flash checks for typing mismatch errors at compile time, and displays an error message if you use the wrong type of value. Therefore, using strict typing also helps to ensure that you do not attempt to access properties or methods that are not part of an object’s type. Strict data typing means the ActionScript editor automatically shows code hints for objects.