• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 288
  • Last Modified:

ActionScript Randomizer

Is there a way in ActionScript to read a directory of smaller .swf files and then randomly display those files order in my movie?
As always, any help is appreciated.

Here's my standard randomizing actionscript I use...but now I need to go to the next step:

filename = ["p1.swf", "p2.swf", "p3.swf" , "p4.swf" , "p5.swf" , "p6.swf" , "p7.swf" , "p8.swf" , "p9.swf" , "p10.swf" , "p11.swf" , "p12.swf" , "p13.swf" , "p14.swf" , "p15.swf" , "p16.swf" , "p17.swf" , "p18.swf" , "p19.swf" , "p20.swf" , "p21.swf" , "p22.swf" , "p23.swf" , "p24.swf"];
i = filename.length;
k = Math.floor(Math.random()*i);
loadMovie(path+filename[k], movieTarget);

chateaumiller
0
chateaumiller
Asked:
chateaumiller
  • 4
  • 3
  • 2
1 Solution
 
RoonaanCommented:
Actionscript cannot read directories. You would have to use a serverside script (php/asp/jsp/coldfusion) to generate a file listing for you.

-r-
0
 
chateaumillerAuthor Commented:
Thank you...yes, everyone has now told me what a loser I am for not knowing that Actionscript cannot read directories. :-)

I still need help on randomizing the out put of the array without repeating a movie that was allready loaded.

Thanks,

chateaumiller
0
 
RoonaanCommented:
Can you explain this constraint: "without repeating a movie that was allready loaded."

Are you loading a new random movie every 30 seconds in a main movie or something?

-r-

0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
EsopoCommented:
>>I still need help on randomizing the out put of the array without repeating a movie that was allready loaded.<<
If what you mean by that is the need to not repeat a movie, you can simply keep track of which movies were already played and check that list before playing the result of a random.

However, I would recommend you do a random sort to the entire array. Once the array has been resorted you play it forward. To sort the array in random you can use something like this:

******************
function randomSort(a, b) {
  k=Math.floor(Math.random()*2); //Return either 0 or 1 randomly

    if (k==0) {
      return (a > b);
    }else{
      return (a < b);
    }
}
 
// Example:
 
myArray = [22, 1, 8, 3, 15, 100];
myArray.sort(); //normal sort
trace(myArray); // output: 1,100,15,22,3,8
 
myArray.sort(randomSort);
trace(myArray); // output will be a random sort

******************
Expanded from: http://code.dreamincode.net/snippet128.htm
0
 
chateaumillerAuthor Commented:
http://www.theonehundred.org

This is the example....the list of images of participants at the bottom shows up every time in the same order.
They are each a seperate .swf file.

I need them to load randomly every time.

Thanks

chateaumiller
0
 
EsopoCommented:
What part of my fully functional script did you have problems with?
0
 
chateaumillerAuthor Commented:
No problems at all...I'm working on it now.
Just did that post to show you what I was working on.

Thanks a ton...testing tonight.

Chateaumiller
0
 
chateaumillerAuthor Commented:
Sorry bought the wait been swamped Esopo...thank you...it is working beautifully.

Chateaumiller
0
 
EsopoCommented:
Good to know. It looks pretty cool too :)
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

  • 4
  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now