Can AS3 or XML "read" files from a directory?

What I want is for flash to grab files from a directory without knowing what files are there. I dont think it’s possible with AS3 but I’m not too sure about XML, and if I can get it into a xml file, then i can ccess it from as3.

The concept might be confusing so an example would be if I had a mp3 player and I wanted to play files from a certain directory but not know what files were in that directory. I would assume XML can “scan” folders for files with a specified exstention and store that information in an array of somesort.

[quote=substance;2295268]What I want is for flash to grab files from a directory without knowing what files are there. I dont think it’s possible with AS3 but I’m not too sure about XML, and if I can get it into a xml file, then i can ccess it from as3.

The concept might be confusing so an example would be if I had a mp3 player and I wanted to play files from a certain directory but not know what files were in that directory. I would assume XML can “scan” folders for files with a specified exstention and store that information in an array of somesort.[/quote]

Hey there substance,

Wandered accross your post… had any joy with this using AS3 since these posts? Or did you use a server side language in the end? What you’re after is exactly the kind of thing im trying to develop, ie use AS3 to read folder contents and then work out which files it wants…

Rjl

Its actually pretty simple. My PHP knowledge is poor, but using an example on this page, heres something quick that should work, it returns all the files in a directory specified (but not subdirectories, but I’m sure you can find an example on the same page if you need that):

import flash.events.Event;
import flash.net.URLLoader;
import flash.net.URLRequest;
import flash.net.URLVariables;
import flash.net.URLRequestMethod;

var urlLoader:URLLoader = new URLLoader ();
var urlRequest:URLRequest = new URLRequest ('whatever.php');
var urlVars:URLVariables = new URLVariables ();

urlVars.folder = 'path/to/folder';
urlRequest.data = urlVars;
urlRequest.method = URLRequestMethod.POST;

urlLoader.addEventListener (Event.COMPLETE, onComplete);
urlLoader.load (urlRequest);
		
function onComplete (evt:Event) : void {
	var xml:XML = XML (urlLoader.data);
	trace (xml);
}
<?php
if ($handle = opendir($_POST['folder'])) {
    $xmlReturn = "<data>";

    while (false !== ($file = readdir($handle))) {
        if ($file != "." && $file != "..") {
           $xmlReturn .= '<file name="'.$file.'" />';
        }
    }
    closedir($handle);
    echo ($xmlReturn.'</data>');
}
?>

Simply paste the actionscript into your timeline, and create a new php file (I chose the name ‘whatever.php’ but it doesn’t matter, as long as you specify it correctly in the actionscript), and paste in the PHP code.