I've been all over the interwebs, including Stack Overflow, for hours, trying to identify a solid, workable example of saving information in Flash into an XML file.
I want to take the positions of two different types of objects and export the lists of each to XML. We'll call the objects ball and bat.
So, I'd love to have the XML look something like:
<objects>
<ball xPos=34 yPos=43/>
<ball xPos=12 yPos=94/>
<bat xPos=1 yPos=39/>
</objects>
Sounds simple enough, but I haven't been able to find a single decent example for exactly what AS3 code can accomplish this. The data is in two vectors of MovieClips, so I'd be using bats[i].x and bats[i].y for input values.
How can I create this XML, and save it somewhere local to view? Thank you for any help at all, this has proved extremely frustrating.
Best Answer
Working with XML in AS3 is really easy, so to expand on TheDarkIn1978's answer with some code:
Creating an XML object:
Use the TheDarkIn1978's to the
XML
class in AS3 to learn more.Saving out your file:
Compressing your XML before saving (with large XML files, this can save a lot):
Loading in a compressed XML, uncompressing it, and retrieving the XML object:
I created a simple tool for compressing/uncompressing XML files. You can get the SWF and source at http://divillysausages.com/blog/xml_compressor_uncompressor if you're interested