[F8] Triggering tweens(frame animations) randomly with AS?
Hi,
I want to know if this is possible and how?
Let's say I have a MC which has a little animation of 10 frames inside it. 1st frame with stop(); action and the last frame with gotoAndStop(1);
Is it possible to trigger this animation like mc.gotoAndPlay(2); after a specified amount of time(in seconds or milliseconds) or in random time intervals?
My aim in doing this is, to randomize the background elements' movements... the thing is, I don't want to have something like a "stardust or rain fx" that is done with duplicateMovieClip... I know some examples for those but my question is related to a specific MC/animation.
I'm using Flash MX 2004, so I'm not sure if you'll need to change some of the code or not.
The following code will choose a random amount of seconds to wait before playing again. Also, it will only play if it isn't currently playing, so it won't interupt it's progress through it's frames.
Code:
var cloudsFun:Function = function () {
if (ran--<=0 and clouds._currentframe == 1 or ran == undefined) {
clouds.gotoAndPlay(2);
ran = random(3)+3;
}
trace(ran);
};
var clouds_int = setInterval(cloudsFun, 1000);
n = Math.round((Math.random()*10)+1);
c = 0;
this.onEnterFrame = function(){
c += n;
if (c >= 100){
this.onEnterFrame = null;
this.gotoAndPlay(2);
}
}
Place this in the first frame of the movieclip.
The numbers used will probably need to be altered to create the right effect based on your frame rate
mike
you can delay the action with a random number. use
[CODE]
APause = setInterval(GoBack, random(30000)+15000);//in milliseconds,30000 is max 15000 is minimum
function GoBack() {
my_mc.gotoAndPlay(2);
}
this will repeat itself every random 15000milliseconds to 30000 milliseconds. You can stop the repeat by using clearInterval(APause); inside of the function GoBack() brackets. This works with flash 8, it should work with mx2004 though too.