Hi there,
Not sure whether this will help you or not but hopefully will get you pointed in the right direction. Sometimes seeing something is easier than explaining. Just create yourself a new movie and throw the following code in frame 1 and test it. Click on the buttons, rollover/out, and watch what happens.
The Math function is needed for the MC method Fade as I use Penners math tweens to achieve most of my movement. (Great book … I suggest to all). The method drawframe is just for simplicity sake and draws the squares you will see.
Play around with it. Create extra buttons to see what you can do. I think it will help you understand the concept. Good luck
//
Math.LT = function(t,b,c,d){
return c*t/d +b;
};
//method to call
MovieClip.prototype.fade = function(startVal, endVal, speed) {
this.begin = startVal;
this.finish = endVal;
this.change = this.finish - this.begin;
this.duration = speed;
this.time = 0;
this.onEnterFrame = function(){
with (this) {
_alpha = math.LT(time++, begin, change, duration);
if (time > duration) delete this.onEnterFrame;
}
};
};
//MC method to draw a square for demo purpose
MovieClip.prototype.drawframe = function(lineColour, fillColour, cw, ch, cx, cy, fillAlpha, linealpha) {
if (itsLalpha == undefined) {
itsLalpha = 100;
}
with (this) {
lineStyle(0, lineColour, linealpha);
beginFill(fillColour, fillAlpha);
moveTo(cx, cy);
lineTo(cx+cw, cy);
lineTo(cx+cw, cy+ch);
lineTo(cx, cy+ch);
lineTo(cx, cy);
endFill();
}
};
/*****************************************************************************/
//clip0 is not fading because it is never a target for any button
var Clip0 = this.createemptymovieclip("Clip0", _global.depthlvl++);
Clip0.drawframe(0xffffff, 0xa51439, 100, 100, 200, 100, 100, 0);
//create the button events to control any clip in this case clip1
var mybutton0 = this.createemptymovieclip("mybutton0", _global.depthlvl++);
mybutton0.drawframe(0xffffff, 0xa51439, 100, 25, 200, 300, 100, 0);
//
mybutton0.onrollover = function() {
Clip1.fade(0, 100, 5);
};
//
mybutton0.onrollout = function() {
Clip1.fade(100, 0, 5);
};
//
mybutton0.onpress = function() {
Clip1.fade(100, 0, 5);
//do whatever else you like here ...
};
//
mybutton0.onrelease = function() {
Clip1.fade(100, 100, 5);
};
/*****************************************************************************/
//this clip fades in and out and is controlled by 2 different MC buttons
//button0 created above and button1 below
var Clip1 = this.createemptymovieclip("clip1", _global.depthlvl++);
Clip1.drawframe(0xffffff, 0xa51439, 100, 100, 325, 100, 100, 0);
//
var button1 = this.createemptymovieclip("button1", _global.depthlvl++);
button1.drawframe(0xffffff, 0xa51439, 100, 25, 325, 300, 100, 0);
//
button1.onrollover = function() {
Clip1.fade(0, 100, 5);
};
//
button1.onrollout = function() {
Clip1.fade(100, 0, 5);
};
//
button1.onpress = function() {
//do whatever else you like here ...
};
//
button1.onrelease = function() {
Clip1.fade(100, 100, 5);
};
stop();