A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: [F8] Triggering tweens(frame animations) randomly with AS?

  1. #1
    AS enemy
    Join Date
    Jul 2003
    Posts
    58

    [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.

  2. #2
    Uses MX 2004 Pro Quixx's Avatar
    Join Date
    Nov 2004
    Location
    U.S.
    Posts
    877
    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);
    Attached Files Attached Files

  3. #3
    Senior Member indogo's Avatar
    Join Date
    Dec 2005
    Posts
    282
    Various ways but a possible simple solution:

    Code:
    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

  4. #4
    Developing For Dunkets mneil's Avatar
    Join Date
    Mar 2007
    Location
    Lincoln City
    Posts
    2,156
    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center