i wrote this today, its simple but pretty cool and works well... im using it as level transition. screen fades to black, call back is called to draw the new level before it fades back to clear.
just thought someone might like it =)
code:
/* --- params ---
xPos/yPos - top left hand corner position
width/height - rectangle sizes
rate - speed at which the fade goes
colour - colour of rectangle
dep - depth to attach clip
callbac - function to call when the rectangle is mid-fade
--- ----- --- */
function fadeOut(xPos, yPos, width, height, rate, colour, dep, callbac) {
var a = 12;
pane = createEmptyMovieClip("pane", dep);
pane._x = xPos;
pane._y = yPos;
pane.onEnterFrame = function() {
if (a>=120) {
rate = -rate;
callbac();
}
drawPane(width, height, a += rate, colour);
if (a<0) {
pane.removeMovieClip();
delete this.onEnterFrame;
}
};
}
function drawPane(width, height, alpha, colour) {
with (pane) {
clear();
beginFill(colour, alpha);
lineTo(width, 0);
lineTo(width, height);
lineTo(0, height);
lineTo(0, 0);
endFill();
}
}
usage example...
code:
fadeOut(20, 25, 360, 250, 4, 0x000000, 1, build);
[m]