Fading Multiple MovieClips

What I’m looking to do is have one button fade in/out fadeBox1_mc
and the other button fade in/out fadeBox2_mc.

I can get one button to fade in and out the graphic with the following code:
Main Timeline

stop();
fadeBox1_mc.onEnterFrame = function() {
if (fade) {
fadeBox1_mc.nextFrame();
} else {
fadeBox1_mc.prevFrame();
}
};

Button:
on (rollOver){
this.fade=true;
}
on (rollOut,dragOut){
this.fade=false;
}

However when I attempt to create another button and make it fade in/out fadeBox2_mc i’m unsuccessfull when adding another fade function with fadeBox2_mc to the main timeline. What would be the most efficient way have having multiple buttons control _mc fades? Thanks a ton!

Sorry, I believe I posted this to the wrong place the first time.

What I’m looking to do is have one button fade in/out fadeBox1_mc
and the other button fade in/out fadeBox2_mc.

I can get one button to fade in and out the graphic with the following code:
Main Timeline

stop();
fadeBox1_mc.onEnterFrame = function() {
if (fade) {
fadeBox1_mc.nextFrame();
} else {
fadeBox1_mc.prevFrame();
}
};

Button:
on (rollOver){
this.fade=true;
}
on (rollOut,dragOut){
this.fade=false;
}

However when I attempt to create another button and make it fade in/out fadeBox2_mc i’m unsuccessfull when adding another fade function with fadeBox2_mc to the main timeline. What would be the most efficient way have having multiple buttons control _mc fades? Thanks a ton!

You should define a variable for each MovieClip, something like this:
[AS]// Frame Actions
fadeMC = function() {
if (this.fade) {
this.nextFrame();
} else {
this.prevFrame();
}
};
fadeBox1_mc.onEnterFrame = fadeMC;
fadeBox2_mc.onEnterFrame = fadeMC;
// Actions for Button controlling fadeBox1_mc
on (rollOver) {
fadeBox1_mc.fade = true;
}
on (rollOut) {
fadeBox1_mc.fade = false;
}
// Actions for Button controlling fadeBox2_mc
on (rollOver) {
fadeBox2_mc.fade = true;
}
on (rollOut) {
fadeBox2_mc.fade = false;
}[/AS]
That should work, I think. =)

http://www.kirupaforum.com/forums/showthread.php?s=&threadid=28548

You have made me such a happy man! Thanks a ton, worked perfectly!

Just so I can be sure…everything i’ve been learning has been by book and tutorial so i’m sure i’m missing a lot. Can you explain to me exactly how this part works:
fadeMC = function() {
if (this.fade) {
this.nextFrame();
} else {
this.prevFrame();
}
};
fadeBox1_mc.onEnterFrame = fadeMC;
fadeBox2_mc.onEnterFrame = fadeMC;

Basically you’re saying “here is what fadeMC does and these _mc follow that command”?

Thanks again!

Yeah, the function is called by the Object when the assigned event occurs, in this case, the onEnterFrame handler. :stuck_out_tongue:

By the way, welcome to kirupa forum! :wink:

PS. I just realized that you posted in both Flash MX and ActionScript sections, please do not crosspost! :-\

I’ll merge both threads.

EDIT. liam’s post looks funny. :stuck_out_tongue: