A Flash Developer Resource Site

Results 1 to 6 of 6

Thread: Loopable?

  1. #1
    Member
    Join Date
    Jun 2009
    Posts
    49

    Loopable?

    Hello all...

    This code produces a random clip from an array. I need it to loop every 3 seconds. Is this possible?

    __________________________________________________ __________

    arr = ["strandA","strandT","strandC","strandG"];

    arr.sort(function(){return Math.floor(Math.random()*3)-1});

    var clip = arr[0];

    this.attachMovie(clip,clip,1,init);

    __________________________________________________ ___________

    Using Flash MX 2004 V7
    Thanks!

  2. #2
    FK'n_dog a_modified_dog's Avatar
    Join Date
    Apr 2003
    Location
    "aaarf"
    Posts
    9,176
    make use of setInterval -
    PHP Code:
    TL this// reference to main timeline
    arr = ["strandA","strandT","strandC","strandG"];

    function 
    bio(){
    arr.sort(function(){return Math.floor(Math.random()*3)-1});
    var 
    clip arr[0]; 
    TL.attachMovie(clip,clip,1,init); 
    };

    bioInterval setInterval(bio,3000); 

  3. #3
    Member
    Join Date
    Jun 2009
    Posts
    49
    Thanks for the reply and the code!!
    You've been a tremendous help for a struggling new programmer :^D

  4. #4
    Member
    Join Date
    Jun 2009
    Posts
    49
    If you don't see my other reply, thanks for the code, it was a big help.

    One more question if you don't mind:

    Is there any way to keep the movie clips on the stage? They disappear as soon as the function repeats (after 3 seconds).

  5. #5
    FK'n_dog a_modified_dog's Avatar
    Join Date
    Apr 2003
    Location
    "aaarf"
    Posts
    9,176
    you must use unique depths to prevent overwriting
    PHP Code:
    TL this// reference to main timeline 
    arr = ["strandA","strandT","strandC","strandG"]; 
    depth 100;

    function 
    bio(){ 
    arr.sort(function(){return Math.floor(Math.random()*3)-1}); 
    var 
    clip arr[0]; 
    TL.attachMovie(clip,clip,depth,init); 
    depth++;
    }; 

    bioInterval setInterval(bio,3000); 
    ps.. change the coordinates of init or each clip will attach to the same position

  6. #6
    Member
    Join Date
    Jun 2009
    Posts
    49
    That makes sense....thanks again!

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