A Flash Developer Resource Site

Results 1 to 5 of 5

Thread: Going Random! (a little help?)

  1. #1
    This way In
    Join Date
    Jan 2001
    Posts
    253

    Going Random! (a little help?)

    Hi guys,
    I have my main .swf, and let us say three MC's waiting on the edge of the stage. What I want is for the script to make a random decision about playing one of these three MC's every few seconds (let's say every four seconds). Can anybody help?

    Thanks very much
    Simon Fox.
    Good lord, it's been a while

  2. #2
    Senior Member tonypa's Avatar
    Join Date
    Jul 2001
    Location
    Estonia
    Posts
    8,223
    You should gibe those 3 mcs instance name like "mc1", "mc2" and "mc3". Now its easy to control them randomly by:

    _root["mc"+(random(3)+1)].play();

  3. #3
    This way In
    Join Date
    Jan 2001
    Posts
    253
    Just assume for a minute that i'm completely clueless, and explain exactly where I should be applying that code? On the MC's? or in the main timeline?

    thanks again,
    Simon Fox.
    Good lord, it's been a while

  4. #4
    Senior Member tonypa's Avatar
    Join Date
    Jul 2001
    Location
    Estonia
    Posts
    8,223
    Here is basic function with timer. This should be placed in the frame in main timeline:
    code:
    this.onEnterFrame = function() {
    //time to wait between playing another mc
    pauseTime = 4000;
    //set timer variable at the start
    if (lastTime == undefined) {
    lastTime = getTimer()+pauseTime;
    }
    //check if time has passed
    if (getTimer()>lastTime) {
    //increase timer
    lastTime = getTimer()+pauseTime;
    //play random mc
    _root["mc"+(random(3)+1)].play();
    }
    };


  5. #5
    This way In
    Join Date
    Jan 2001
    Posts
    253
    Much obliged tonypa, Very very helpful,
    Thanks alot,
    Simon.
    Good lord, it's been a while

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