Example Name: DirectoryList.fla
Language: ActionScript 1.0
Version: 1.0.0
Code:
#include "NetServices.as"
// The directory to list the contents of
var theDirectory = "e:\\sample";
var myURL = "http://localhost/flashservices/gateway";
if (initialized == null) {
initialized = true;
NetServices.setDefaultGatewayUrl(myURL);
var my_conn = NetServices.createGatewayConnection();
var myService = my_conn.getService("com.oreilly.frdg.Directory");
}
// Call the remote service to retrieve a directory, given the path
myService.getDirectory(new MyResponder(),theDirectory);
// Set up the Tree control, named directory_tree
var myRootNode = new FTreeNode(theDirectory).setIsOpen(true);
directory_tree.setRootNode(myRootNode);
// Responder object for the directory list, with private methods
function MyResponder() {
this.onResult = function(myResult) {
listDirectory(myResult, myRootNode);
directory_tree.refresh();
}
this.onStatus = function(myStatus) {
trace("Error: "+ myStatus.description);
}
function listDirectory(myArray, node) {
for (var i=0; i< myArray.length; i++) {
if(myArray[i] instanceof Object) {
var new_tree_node = new FTreeNode(myArray[i].directory);
node.addNode(new_tree_node);
listDirectory(myArray[i].files, new_tree_node);
}else{
node.addNode(new FTreeNode(getFile(myArray[i]), getFile(myArray[i])));
}
}
};
function getFile(filePath) {
var lastSlash = filePath.lastIndexOf("\\");
if (lastSlash != -1) filePath = filePath.substring(lastSlash+1);
return filePath;
}
}
Download code text
Download chapter example files