Now look at the default responder handler:
private function getList_result(e:*):void
{
CursorManager.removeBusyCursor();
if(e is Array)
{
if(e.length)
{
delete currItem.node[0];
var node:XML;
for each(var item:Object in e)
{
currItem.@loaded = "true";
node = XML("<node label='"+item.name+"' loaded='false' data='"+currItem.@data+"/"+item.name+"'></node>");
if(item.is_dir)
{
node.node = <node label="" data="" loaded="false"></node>
}
currItem.node += node
}
} else {
delete currItem.node[0];
currItem.@loaded = "true";
tree.setItemIcon(currItem, tree.getStyle("folderOpenIcon"), tree.getStyle("folderClosedIcon"));
}
}
}
First see at the argument class: *
We can't use a ResultEvent or a RecordSet object, and so we don't know which object will return amfphp (in this case it will be an array).
So if the result object e is an Array (the keyword "is" it's the same as the previous instanceof) then:
if the array has at least one element (the remote directory has at least one file/folder inside):
for each(var item:Object in e)
For every element in the "e" array give me an Object item (this item will contain name ans id_dir properties, as defined in php). For every item add a new "node" xml element to our currItem xml variable (remember? currItem was a reference to the opening node...).
If item.is_dir is true, then create a temporary node just for letting flash to add the "+" icon beside the folder node (this folder will be parsed next time user will click on the "+" icon...). Finally set currItem.@loaded = "true";, so next time we won't parse this directory again.
This new way of use for loops it's the same as I have written:
var item:Object;
for(var a:uint = 0; a < e.length; a++){
item = e[a];
}
As you can see the new "for each" style reduce the code we have to write.
6. Conclusion
The conclusion is that with AS3 you can still use flash remoting even if with some limitations expectially in the results..
