dcsimg
A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: random waiting time

  1. #1
    Senior Member kidpablo's Avatar
    Join Date
    Aug 2001
    Location
    UK
    Posts
    460

    random waiting time

    I have a movieclip which contains an animation. Instead of the animation playing straight away, I'd like it to wait for a random amount of time (between 0-10 seconds). Is there a piece of script I can attach to the movie clip, or is it more complicated than this?

    Thanks.

  2. #2
    Senior Member catbert303's Avatar
    Join Date
    Aug 2001
    Location
    uk
    Posts
    11,222
    Hi,

    You could attach this event to the movie clip

    onClipEvent(load) {
    this.stop();
    delay = Math.round(Math.random() * 10000);
    playTime = getTimer() + delay;
    }
    onClipEvent(enterFrame) {
    if (this._currentframe == 1) {
    if (getTimer() > playTime) {
    this.play();
    }
    }
    }

  3. #3
    The code works great except once the animation plays randomly the first time it loops and loops without the random delay command reworking each time. How could I do this? I tried the following code but it didn't work.

    Cheers,

    Leao

    Code:
    onClipEvent(load) {
    this.stop();
    delay = Math.round(Math.random() * 5000);
    playTime = getTimer() + delay;
    }
    onClipEvent(enterFrame) {
    if (this._currentframe == 1) {
    if (getTimer() > playTime) {
    this.play();
    }
    }
    if (this._currentframe == "lastframe") {
    delay = Math.round(Math.random() * 5000);
    playTime = getTimer() + delay;
    if (getTimer() > playTime) {
    this.gotoAndPlay(2);
    }
    }
    }

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