Search code examples
androidactionscript-3airmp3file-get-contents

AS3 Get local folder mp3 contents into Array - Randomize


50 RANDOM QUOTES

Looking to create an AS3 air for android app that loops through folders and randomly selects from all the mp3s in a folder and plays one of them. After it is done playing it will go to the next folder and do the same until it has finished playing 50 random quotes.

FOR EXAMPLE:

  1. The code would start with A1 and open folder 01 and randomly play one of the 10 mp3s.
  2. When audio is over it would open folder 02 and randomly play one of the 7 mp3s.
  3. After looping through all folders in A1 it would do the same thing all over in A2 - A5...

WHAT I REALLY NEED HELP WITH IS...

Using AS3 how do I select the contents of local folder  or sub 
folder and put them into an array and randomly choose one
from that array?

If I know how to do that then I can use this for the audio files and later apply this same structure to call 50 random images.

NOTE The loop has to go in this order for a reason I will not explain here.

I included an IMAGE so you can visualize what I am trying to do.



enter image description here


Solution

  • This code gets contents of the folders.

    import flash.filesystem.File;
    
    var desktop:File = File.applicationDirectory.resolvePath("TheFilePathYouChoose/Choice");
    var files:Array = desktop.getDirectoryListing();
    for (var i:uint = 0; i < files.length; i++)
    {
     trace(files[i].nativePath); // gets the path of the files
     trace(files[i].name);// gets the name
    
    }