A client wants to be able to just put mp3 files into a folder and have a flash object load all mp3 files from that folder, and does not want to deal with XML. Is this possible? I know I could easily do this with an XML file, but I'm not sure how to do it without one.
views:
576answers:
3I'm assuming the client doesn't want to have to manually list the mp3 files in a XML file, but either way, a list of the files has to be exposed to the flash component for it to be able to pull the files.
One way to do this would be a server side script that'll list the files for that given directory and return this list in some XML format (entirely automated, no manual XML file creation). Writing such a server side script should be fairly simple (using PHP, for example).
Process:
- Fetch a list of files using an HTTP request from the client to the server side script.
- Process the list of files and do whatever you intended to do with them.
Hey Matt,
are we talking about local files or server files? AIR or SWF? If you are using AIR you can do this with local files, using the File object.
Working with swf content on the server, you could do this with php (or other language) script that can grab the names of all the files. In php, take a look at the readdir method.
Unfortunately there is no native method in ActionScript outside of AIR.
Hope that helps.
Tyler.
You could use a text file instead of a XML file.
Given a text file:
assets/song1.mp3
assets/song2.mp3
assets/song3.mp3
assets/somg4.mp3
This code will load the text file and split each song name into the elements of an array:
package
{
import flash.display.Sprite;
import flash.events.Event;
import flash.net.URLLoader;
import flash.net.URLRequest;
public class LoadFileTest extends Sprite
{
public static const FILE_LIST_PATH:String = "mp3List.txt";
public function LoadFileTest()
{
var urlRequest:URLRequest = new URLRequest(FILE_LIST_PATH);
var urlLoader:URLLoader = new URLLoader();
urlLoader.addEventListener(Event.COMPLETE, processTextFile);
urlLoader.load(urlRequest);
}
public function processTextFile(event:Event):void
{
var loader:URLLoader = URLLoader(event.target);
var textFile:String = loader.data;
var mp3UrlList:Array = textFile.split("\n");
trace(lines);
}
}
}
Another idea is to use a common naming scheme (e.g. song1, song2, song3, etc) and know how many songs you have in code. That way you can write a simple loop (from 1 to the number of songs) and load them that way.