AS 3.0 - help me pls (out of topic)

For international community members
Responder
Avatar de Usuario
Morphid
Site Administrator
Site Administrator
Czech Republic
Mensajes: 86
Registrado: Sab Dic 25, 2010 12:48 am
Ubicación: Czech Republic
Contactar:

AS 3.0 - help me pls (out of topic)

Mensaje por 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
Mensajes: 2898
Registrado: Vie Jul 28, 2006 10:58 am
Ubicación: Bialystok, Poland

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

Mensaje por 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()
Avatar de Usuario
Morphid
Site Administrator
Site Administrator
Czech Republic
Mensajes: 86
Registrado: Sab Dic 25, 2010 12:48 am
Ubicación: Czech Republic
Contactar:

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

Mensaje por Morphid »

Thanks very much =))
Avatar de Usuario
Morphid
Site Administrator
Site Administrator
Czech Republic
Mensajes: 86
Registrado: Sab Dic 25, 2010 12:48 am
Ubicación: Czech Republic
Contactar:

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

Mensaje por 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).

Código: Seleccionar todo

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:

Código: Seleccionar todo

<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..:

Código: Seleccionar todo

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