Prototype?

Just curious here…

I have, let’s say, 50 movie clips.

I want the movie clips to do something on rollover… the will all do slightly similar things

on(rollover){

do x; //where x will be a variable
}

Is there actually a way that will save me from adding the code to each button?

Meaning, I don’t want to do,

function doit(){}

button1.onRollover=doit;
button2.onRollover=doit;
button3.onRollover=doit;

Im thinking protoype? Hmm… Pom, c’mon dude. Although I understand the basic concept, I simply have not applied it to date.

if they were all members of a unique class, you could add the rollOver action to the whole class, but you’d still have to add each button to the class.

if they’re all stored in an array you can loop through the array.

if they’re all in a movie clip you can do a for in loop through the contents of the clip, provided there’s nothing else in the clip.

if they’re all named to that naming convention you could use a while (or a for loop) loop:


var i = 50;
while(i--){
   _root["button"+i].onRollOver = doit;
};

<bowing> Thank you, Supra. That is exactly what I wanted. I tried the loop method.

I haven’t messed with class much, yet… but I can feel it coming soon. I keep reading and reading the prototype stuff, so I can start thinking in those terms. Before, I would just try to use the tools I knew to solve any problem. Well, some cannot be solved without protoype, classes, etc… or, at least, not in a simple fashion.

Again, thanks for the help.