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());

The code for the button :

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

Thank you!