How to write an XML file?

I am a newbie to actionscript and I was hoping someone might help with this.
I am trying to load an xml file into my movie and then when a button is pressed write the xml file.

Here’s the code (I’ve put this code on a new layer, first frame):
xmlData = new XML();
xmlData.ignoreWhite = true;
xmlData.onLoad = function(success) {
if (success) {
trace('data.xml loaded. Contents are: '+this.toString());
}
};
xmlData.load(“data.xml”);

The code for the button :

on(press){
var event = 1;
trace(event);
var element:XMLNode = xmlData.createElement(“element1”);
xmlData.appendChild(element);
trace(xmlData);
}
Practically what I want is that the value of the variable event gets written in the XML file.
Can someone help me?

Thank you!