...

View Full Version : How to add replay button to this animation?



Uzair
04-22-2009, 08:40 AM
Please have a look at the below action script, I got it somewhere on the internet. The transition is working fine but it stops after playing for 1 time. I wanna add a Replay Button so I could be able to play the animation again & again. Please help me how can I add a replay button?

Here is the code...

//Declare variables
xspacing = box._width;
yspacing = box._height;
depth = 0;
box._visible = 0;
smoothness = 90;
//Calculate positions and values
amH = Math.ceil(image._width/box._width);
amV = Math.ceil(image._height/box._height);
border._height = image._height+1;
border._width = image._width+1;
border._x = image._x-0.5;
border._y = image._y-0.5;
//Create grid
for (i=0; i<amH; i++) {
for (var k = 0; k<amV; k++) {
box.duplicateMovieClip("box"+depth, depth);
cur = this["box"+depth];
cur._x = image._x+(xspacing*i);
cur._y = image._y+(yspacing*k);
depth++;
}
}
function fadeOut(startboxnr, speed) {
fadeMC(startboxnr, speed);
}
function fadeMC(mcnr, speed) {
this["box"+mcnr].onEnterFrame = function() {
this._alpha -= speed;
if (this._alpha<=smoothness) {
this.onEnterFrame = null;
continueFade(this, speed);
mcnr += 1;
fadeOut(mcnr, speed);
}
};
}
function continueFade(mc, speed) {
mc.onEnterFrame = function() {
this._alpha -= speed;
if (this._alpha<=0) {
delete this.onEnterFrame;
}
};
}
fadeOut(0, 5);

gnomeontherun
04-22-2009, 10:24 AM
You need something to reset the alpha property. This is a simple reset if you put it on a button to reset the visibility to 100 for box0.


on (release)
{
box0._alpha = 100;
}

Uzair
04-22-2009, 10:34 AM
Where to put that code? When I paste your code at the bottom of the action script window & then try to run, flash gives me a warning that such command is only associated with the buttons. Also, animation doesn't work.

Please help, I am a newbie & trying to replay the animation :(

gnomeontherun
04-22-2009, 02:12 PM
Right, that is because it should go on a button instead. Make a button that says replay or something, then attach this code to it.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum