AS 3.0 - help me pls (out of topic)

For international community members
Post Reply
User avatar
Morphid
Site Administrator
Site Administrator
Czech Republic
Posts: 86
Joined: Sat Dec 25, 2010 12:48 am
Location: Czech Republic
Contact:

AS 3.0 - help me pls (out of topic)

Post by Morphid »

Is there anybody who knows anything about ActionScript 3.0? I need help with writing data to external XML file (load XML file, write data and further "save" it to the XML file.

Thanks a lot.
Radzio
Site Administrator
Site Administrator
Poland
Posts: 2898
Joined: Fri Jul 28, 2006 10:58 am
Location: Bialystok, Poland

Re: AS 3.0 - help me pls (out of topic)

Post by Radzio »

http://www.republicofcode.com/tutorials/flash/xml/

When you're done with XML, you can save the contents of an object like any normal string to a regular file using method .toXMLString()
User avatar
Morphid
Site Administrator
Site Administrator
Czech Republic
Posts: 86
Joined: Sat Dec 25, 2010 12:48 am
Location: Czech Republic
Contact:

Re: AS 3.0 - help me pls (out of topic)

Post by Morphid »

Thanks very much =))
User avatar
Morphid
Site Administrator
Site Administrator
Czech Republic
Posts: 86
Joined: Sat Dec 25, 2010 12:48 am
Location: Czech Republic
Contact:

Re: AS 3.0 - help me pls (out of topic)

Post by Morphid »

Ok, I've a code which reads data from external XML file. Now I want to add a new user to this xml and save it - when I close the Flash app and run it again, "the new user" will be there (in xml).

Code: Select all

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

var myXML = new XML();
var xmlReq:URLRequest = new URLRequest("../accounts.xml"); 
var xmlLoader:URLLoader = new URLLoader(xmlReq); 
xmlLoader.addEventListener(Event.COMPLETE, xmlLoaded);
	
function xmlLoaded(event:Event):void { 
     myXML = XML(xmlLoader.data);
     trace(myXML);
}
This is my XML:

Code: Select all

<accounts>
  <user>
    <name>Morphid</name>
    <pass>dog8862</pass>
  </user>
  <user>
    <name>Host</name>
    <pass>cat94</pass>
  </user>
</accounts>
and I added a new object to myXML (I don't know sure that this is the right class for adding an object to XML.. ), but when I see changes (trace(myXML) again..), these new elements are there..:

Code: Select all

myXML.appendChild(<user><name>NewUser</name><pass>rat12</pass></user>);
trace(myXML);
Post Reply