View Full Version : swapping depths with a fade
mprzybylski
January 6th, 2005, 06:55 PM
Hello,
I want to swap depths on movieclips overlaying each other but instead of the new clip on rollover just popping up over the other one, i want it to fade into the top.
here is an attached .fla file in mx2004 format.
for those not using 2004, here is the code:
but1.onRollOver = but2.onRollOver = but3.onRollOver = but4.onRollOver = function() {
this.swapDepths(getNextHighestDepth());
};
Also, is there a way to streamline this code so i dont have to type the button instance names every time i add another?
scotty
January 7th, 2005, 04:03 AM
For the streamline
var nrofButtons = 4;
for (i=1; i<=nrofButtons; i++) {
var but = this["but"+i];
but.onRollOver = function() {
this.swapDepths(getNextHighestDepth());
};
}
scotty(-:
mprzybylski
January 7th, 2005, 08:14 AM
thanks scotty, any idea how to do the fade?
scotty
January 7th, 2005, 10:07 AM
For the fade I've duplicated the mc, so you have a solid background when you fade.
Else on rollover the mc disappeared and then fades in, if you want that, simply skip the duplicate line:)
var nrofButtons = 4;
for (i=1; i<=nrofButtons; i++) {
var but = this["but"+i];
but.duplicateMovieClip("btn"+i, i);
but.onRollOver = function() {
this._alpha = 0;
this.swapDepths(getNextHighestDepth());
this.onEnterFrame = fadeIn;
};
}
MovieClip.prototype.fadeIn = function() {
this._alpha += 10;
if (this._alpha>=100) {
this._alpha = 100;
delete this.onEnterFrame;
}
};
scotty(-:
mprzybylski
January 7th, 2005, 07:28 PM
that is VERY close scotty, only problem is that when it fades in, lets say button 3 (the red one), it fades from behind the two buttons around it, instead of the last one that was on the highest depth, so it looks like it fades out first and then in to where it should be, know what i mean? any way to correct this?
thanks a ton by the way.
scotty
January 8th, 2005, 05:50 AM
Maybe like this?
var nrofButtons = 4;
var startDepth = 100;
var dupDepth = startDepth-nrofButtons;
for (i=1; i<=nrofButtons; i++) {
var but = this["but"+i];
but.swapDepths(startDepth+i);
but.i = i;
but.duplicateMovieClip("btn"+i, dupDepth+i);
but.onRollOver = function() {
this._alpha = 0;
this.swapDepths(getNextHighestDepth());
this.onEnterFrame = function() {
this.fadeIn(this.i);
};
};
}
MovieClip.prototype.fadeIn = function(n) {
this._alpha += 10;
if (this._alpha>=100) {
this._alpha = 100;
this._parent["btn"+n].swapDepths(getNextHighestDepth()-nrofButtons);
delete this.onEnterFrame;
}
};
scotty(-:
mprzybylski
January 8th, 2005, 03:56 PM
scotty, that is awesome but still a little buggy on the initial rollovers of some of the squares, where if i roll over something and then roll over other ones, then roll over that something again, the first fade in is kinda still doing that same thing.
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.