unified Rollover function on multiple MC's
Hi all,
I'm trying to code a variable rollover for a sequence of MCs on the stage.
I have 3 buttons (MovieClips) on the stage and each time one is rolled over I'm making a different movieclip appear.
So I've done this in a root timeline frame script:
//put an empty container movieclip on the stage
containerMC = _root.createEmptyMovieClip("container", this.getNextHighestDepth());
//button 1 - "but1" is my linked instance name and Content 1 is my content movieclip
but1.onRollOver = function() {
trace("You rolled over on the movie clip '"+this._name+"'.");
newContent=_root.attachMovie("Content1","container",containerMC.getDepth());
newContent._x=300;
newContent._y=200;
};
and so on for each button (1, 2 and 3).
As you can imagine if there were 20 buttons there is a lot of uneccessary duplication.
What I've considered is, as they are sequential I should be able to read "but"+i and "content"+i and I could push the button names and content names into an array. The thing I'm having trouble with is, how do I write the function so it checks which clip is rolled over and then attaches the corresponding content movieclip?
Ultimately I would like the script to check how many buttons there are on the stage and simply iterate for that number (so I don't have to specify how many there are to loop through i.e. numOfButtons = 4), But not sure how to go about it.
As you can see the code could be the same for each button, if I could read the movieclip rolled over and attach the function variably.
In summary what I'm trying to do is have a single function for all rollover buttons named but1 to but n.
Any guidance would be appreciated.
Chris