A Flash Developer Resource Site

Results 1 to 7 of 7

Thread: Load a series of movieclips in random order

  1. #1
    Junior Member
    Join Date
    Oct 2010
    Posts
    5

    Load a series of movieclips in random order

    I have 9 movie clips which I want to load in random order, so that viewers who come to the webpage don't always see the same thing. I have them set up as 9 frames within another mc.
    I'm no Actionscript expert (far from it) but I found a script on one of these forums (it's from a very old thread though) that does just what I need EXCEPT it always displays the first one first, and then the rest in random order. I tried making the first frame empty, but then there was a big lag before it showed anything, because of the timer. Any suggestions, or perhaps a different way altogether? Here's the script I used:


    myMc.stop();
    time = getTimer();
    wait = 500;//1000ms = 1 second
    _root.onEnterFrame = function(){
    if (getTimer() > time+2000){
    myMc.gotoAndStop(random(myMc._framesloaded)+1);
    time = getTimer();
    }
    }


    I'm using Flash CS4 but Actionscript 2. Thanks!

  2. #2
    Senior Member
    Join Date
    Aug 2006
    Posts
    322
    Actionscript Code:
    myMc.stop();
    time = getTimer();
    var myMC_h=22;
    wait = 500;//1000ms = 1 second
    _root.onEnterFrame = function() {
        if (getTimer()>time+2000) {
            //myMc.gotoAndStop(random(myMc._framesloaded)+1);
            for (i=0; i<9; i++) {
                this["myMC"+i].removeMovieClip();
                this.attachMovie("myMC","myMC"+i,this.getNextHighestDepth(),{_x:100, _y:100+this._y+myMC_h*i});
                this["myMC"+i].gotoAndStop(random(10)+1);
            }
            time = getTimer();
        }

    };


    marlopax

  3. #3
    Junior Member
    Join Date
    Oct 2010
    Posts
    5
    Thanks but - this does exactly the same thing! Always starts by showing frame 1 of the movie clip.
    Any other ideas?
    By the way, each of the movie clips within my main mc are 100 frames long. I changed the time to 9000, to give me the time I need for each one.
    I'm not sure what this line does:
    wait = 500;//1000ms = 1 second
    When I commented it out, it made no difference.

  4. #4
    Senior Member
    Join Date
    Aug 2006
    Posts
    322
    Actually the var wait is to make the interval dynamic. For instance:

    if (getTimer()>time+2000) {

    change to

    if (getTimer()>time+wait) {

    so if you change the value of var wait the interval of time will change.

    this does exactly the same thing! Always starts by showing frame 1 of the movie clip.
    what exactly you mean?

    I changed the time to 9000, to give me the time I need for each one.
    this seems that you want to wait for 9000 ms on each frame of your hunderd frame movies, right?

    post the fla.

    marlopax

  5. #5
    Junior Member
    Join Date
    Oct 2010
    Posts
    5
    I'm fine with the pacing and yes, 9000 seems about right, no problem there.
    The problem is that when the script runs, we're already seeing frame #1 of the mc. I want the order of the whole sequence to be random, starting with the first frame we see. Should the script be on a different frame than the mc?

    Here's the fla. I swapped out differently-colored number sequences for the photos, for smaller file size. The first set of numbers is white. How can I change it so that it's random?

    Thank you!
    Attached Files Attached Files

  6. #6
    :
    Join Date
    Dec 2002
    Posts
    3,518
    Code:
    stop();
    
    var time = getTimer();
    var myMC_h = 22;
    var wait = 9000;//1000ms = 1 second
    
    myMC._visible = false;
    do {
    	myMC.gotoAndStop(random(myMC._framesloaded)+1);
    } while (myMC._framesloaded<myMC._totalframes);
    myMC._visible = true;
    
    _root.onEnterFrame = checkUpdate;
    
    function checkUpdate() {
    	if (getTimer()>time+wait) {
    		myMC.gotoAndStop(random(myMC._framesloaded)+1);
    		for (i=0; i<9; i++) {
    			this["myMC"+i].removeMovieClip();
    			this.attachMovie("myMC","myMC"+i,this.getNextHighestDepth(),{_x:100, _y:100+this._y+myMC_h*i});
    			this["myMC"+i].gotoAndStop(random(10)+1);
    		}
    		time = getTimer();
    	}
    }

  7. #7
    Junior Member
    Join Date
    Oct 2010
    Posts
    5
    Visible = false! A brilliant solution, thank you so much! Works like a charm.

Tags for this Thread

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