1 Reply Latest reply on Jun 2, 2006 5:39 AM by blemmo

    doubt with flash XML

    Level 7
      hi all

      i got a doubt with creating XML objects using classes. the case is:
      there should be a class like CreateXML which will intialise an XML object
      and has methods to add new elements to the XML. how to create new XML
      elements/nodes to this class?

      is there anyway to create and write into an external XML file using
      actionscript?
      can we make an XML object updated with new data elements on the runtime
      itself?

      hopefully waiting...
      aneesh.


        • 1. Re: doubt with flash XML
          blemmo Level 1
          Hi,

          most of your questions are answered in the Flash Help >> check out the XML class.
          Your custom class would just have to contain a XML object and use the methods provided by the XML class, like this:

          class CreateXML{

          private var theXML:XML;

          public function CreateXML(){
          this.theXML = new XML();
          }
          public function addNode(name:String){
          var node:XMLNode = this.theXML.createElement(name);
          this.theXML.appendChild(node);
          }
          ...
          }

          To save the XML, you'll need a server or 3rd party software; Flash cannot save files itself. The XML class has a send() method, this can be used to send the XML to a server, which then can save it.
          It also has the load() method, to load a XML file on runtime. So you may load a file, change it and send it back.

          When using XML.load(), you should avoid the cache if the remote XML changes a lot. To do this, you can add a timestamp to the URL, so Flash will always get the file from the server and not the cached version:
          theXML.load("filename.xml?nocache="+getTimer())

          hth,
          blemmo