FORUMS: list search recent posts

Script to Stop Animation after 15 seconds

COW Forums : Adobe Flash

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Lisa Koza
Script to Stop Animation after 15 seconds
on Jun 25, 2010 at 12:24:59 am

Hi there,

I know basic flash, and I added some action script 2.0 into a flash banner for some fireworks. It sits on one frame, and I need it to stop doing it's thing after 15 seconds, and I haven't a clue! ;-)

I have text moving too, it's in a movie symbol, and I know to use stop () to get that done with, but this other code is just crazy.

Any coders know of a simple line to add or something??

Thanks!

Lisa


// Fireworks Creating
fireworks = function (x1, y1, r, g, b, p) {
for (var i:Number = 0; i<r; i++) {
this.attachMovie("fireworks_mc1", "r"+i, i);
_root["r"+i]._x = x1;
_root["r"+i]._y = y1;
}
for (var i:Number = 0; i<g; i++) {
this.attachMovie("fireworks_mc2", "g"+i, r+i);
_root["g"+i]._x = x1;
_root["g"+i]._y = y1;
}
for (var i:Number = 0; i<b; i++) {
this.attachMovie("fireworks_mc3", "b"+i, r+g+i);
_root["b"+i]._x = x1;
_root["b"+i]._y = y1;
}
for (var i:Number = 0; i<p; i++) {
this.attachMovie("fireworks_mc4", "p"+i, r+g+b+i);
_root["p"+i]._x = x1;
_root["p"+i]._y = y1;
}
};
// fireworks(x1,y1,red,green,blue,purple)
fireworks_start = function () {
// Number of Red Particle
var red:Number = (Math.random()*20);
// Number of Green Particle
var green:Number = (Math.random()*20);
// Number of Blue Particle
var blue:Number = (Math.random()*20);
// Number of Purple Particle
var purple:Number = (Math.random()*20);
// Fireworks x Coordinate
var x1:Number = (Math.random()*(Stage.width-180))+40;
// Fireworks y Coordinate
var y1:Number = (Math.random()*(Stage.height-180))+40;
// add spark light
_root.attachMovie("light", "light", 3000);
_root.light._x = x1;
_root.light._y = y1;
// Fireworks Function Command
fireworks(x1, y1, red, green, blue, purple);
};
// Fireworks Generating time (1000 millisecond = 1 second)
fireworks_time = setInterval(fireworks_start, 1000);
// Fireworks stop command is here.
// clearInterval(fireworks_time);


Return to posts index

Mike Smith
Re: Script to Stop Animation after 15 seconds
on Jun 25, 2010 at 9:18:33 am

OK, so your code has been a bit mangled on pasting. The Cow functions strip out angle brackets > < , for security. You can overcome this by selecting your code and clicking the CODE button just above the text entry box in the cow submit message page.

So, this is without testing.

It looks like your (copied?) code includes a stop function at
// Fireworks stop command is here.
// clearInterval(fireworks_time);

so if you were to uncomment the clearInterval function by taking out the double slashes, and devise a suitable counter or if loop for when to execute clearInterval, that that might work ...

One approach would be to set a variable on page load, and then increment it each time your fireworks_start functions runs, then run your clearInterval when that counter reaches 15 (or your target time ..)

you could try adding at the start of your code

fireworksCount = 0 ;
fireworksLimit = 15 ;

then insert lines at the start of your fireworksStart function so it reads

fireworks_start = function () {
fireworksCount += 1;
if (fireworksCount == fireworksLimit) {
// trace("stop please");
clearInterval(fireworks_time);
}
// Number of Red Particle
and then follows on as you have it

You can change the number in the fireworksLimit if you want, obviously. This is in seconds since your interval is running in one second (1000 millisecond) jumps.


There's a bit more at
http://www.republicofcode.com/tutorials/flash/setinterval/





Return to posts index

Lisa Koza
Re: Script to Stop Animation after 15 seconds
on Jun 30, 2010 at 9:21:20 pm

hey Mike, thanks so much......I never received an email letting me know you responded, and I figured out another way to get it to stop. Thank you though, so much! :)

Lisa


Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2018 CreativeCOW.net All Rights Reserved
[TOP]