PDA

View Full Version : reusable button functions?


mgd2004
05-24-2004, 09:03 AM
I'm looking for an easy way to set have 55 buttons perform the same onRollOver and onRollOut functions. Basically, when the movieClip that is acting as button is rolledOver, I want the alpha to change to 80, when it's rolledOut, I want the alpha back to 20.

Here's what I have so far... Any help would be greatly appreciated.



// Create movieClip ARRAY
movieClip_array = new Array ();
movieClip_array[0] = btn_step0_mc;
movieClip_array[1] = btn_step1_mc;
movieClip_array[2] = btn_step2_mc;
movieClip_array[3] = btn_step3_mc;
movieClip_array[4] = btn_step4_mc;
movieClip_array[5] = btn_step5_mc;
movieClip_array[6] = btn_step6_mc;
movieClip_array[7] = btn_step7_mc;
movieClip_array[8] = btn_step8_mc;
movieClip_array[9] = btn_step9_mc;
movieClip_array[10] = btn_step10_mc;
movieClip_array[11] = stage1_mc;
movieClip_array[12] = stage2_mc;
movieClip_array[13] = stage3_mc;


for(x=0;x<=(movieClip_array.length-1);x++){
currentButton = movieClip_array[x];

currentButton.onRollOver = function() {
currentButton._alpha = 80;
trace(currentButton);
}
}


Ultimately, I would like the onRelease function load the movieClip_array[x] into a movieClip on the main timeline.

Do I have the right thinking or am I way off?

Matt :confused:

CyanBlue
05-24-2004, 09:21 AM
Howdy and Welcome... :)

You could try this???for (x = 0 ; x <= (movieClip_array.length - 1) ; x++)
{
currentButton = movieClip_array[x];
currentButton.onRollOver = function()
{
_level0[this]._alpha = 80;
trace(_level0[this]);
};
}

mgd2004
05-24-2004, 09:28 AM
CyanBlue,

It seems to only trace "_level0"

Is there a way to create generic function that I can assign to each button individually?

CyanBlue
05-24-2004, 09:40 AM
Um... This one works...btn_arr = new Array(oval0_btn, oval1_btn, oval2_btn, oval3_btn, oval4_btn);

for (x = 0 ; x < btn_arr.length ; x++)
{
eval(btn_arr[x]).onRollOver = function ()
{
this._alpha = 50;
}
eval(btn_arr[x]).onRollOut = function ()
{
this._alpha = 100;
}
}

mgd2004
05-24-2004, 09:52 AM
That seemed to work just fine!

Thanks for your help.