Recursive constructing of an xml object in flash
January 24, 2005 10:53 AM
Subscribe
I need help with recursive constructing of an xml object in flash.
Google just doesn't cut it for me - maybe you can [+]
Say i've got a directory of dragable files and folders in flash. And i want to save the structure of it in xml. The folders can contain folders that contain folders and so on.
How do i go about creating the xml that reflects this structure - as far as i understand i have to make some kind of recursive function that places each object in the right place in the xml-object. But I can't get my head around it.
First of all i would like to know if what i want has a name (i know its not a recursive parser - is it a compiler?=
Second helpful code-snippets, code-outlines or tutorials would be very greatly appreciated.
Thank you all very much for the anticipated solution to my problems.
posted by FidelDonson to computers & internet (3 comments total)
The best way to think of recursion is a function that calls itself with a smaller set of the problem.
You'd probably want something that's logically like this, (sorry for non-functioning code, I'm in a hurry and my actionscript is lacking)
function parse_directory (xml_structure, directory_name)
{
open (directory_name)
for each file in directory
{
add file to xml_structure
if (file is a directory)
parse_directory (xml_structure, file)
}
}
The above will recursively go through your directories, and sub directories, adding them to your XML.
posted by robinw at 2:05 PM on January 24, 2005