Note that there are some explanatory texts on larger screens.

plurals
  1. POAutosaving to xml using fileReference.Save without having a Save As dialog come up
    primarykey
    data
    text
    <p>I am trying to save data gathered from within my app to it's accompanying external xml file called <code>data.xml</code>. I am using the <code>fileReference.save</code> method but it just doesn't seem to be doing the job:</p> <pre><code>function parseXML(xmlData:XML):void { trace("Parsing:"); trace("-----------------"); var itemIndex:uint = event.currentTarget.index; delete data.item[itemIndex]; fileReference.save(data, "data.xml"); trace(xmlData); } </code></pre> <p>Unfortunately, this causes a 'Save As' dialog box to pop up asking the user where they would like to save the xml file (when what I really want to happen is for the data.xml file in the project's directory to be overwritten automatically without any say on the part of the user).</p> <p>I have heard that <code>FileStream</code> is the way to go (especially being I am going to deploy this on Air for iOS), but I don't know how to implement it. </p> <p>Any ideas?</p> <p><strong>EDIT:</strong> I have updated my question with the suggestion below, but it still doesn't work. The <code>data.xml</code> file is in the same directory called 'RecipeMatcher2' on my Desktop i.e. /Desktop/RecipeMatcher2/ (I am using Mac OS X), but I also want it to resolve to whatever path the file will be stored in when on the iPhone.</p> <pre><code>function parseXML(xmlData:XML):void { trace("Parsing:"); trace("-----------------"); var itemIndex:uint = event.currentTarget.index; file = File.applicationStorageDirectory; file = file.resolvePath("data.xml"); delete data.item[itemIndex]; var writeStream:FileStream = new FileStream(); writeStream.open(file, FileMode.WRITE); writeStream.writeUTFBytes(data.toXMLString()); writeStream.close(); trace('xml file saved'); } </code></pre> <p>I originally load my xml data like so:</p> <pre><code>loader = new URLLoader(); // listens to see if data has fully loaded// loader.addEventListener(Event.COMPLETE, dataLoaded); //loads local xml file with URLrequest method// loader.load(new URLRequest("data.xml")); </code></pre> <p>and here are my public vars relevant to this question:</p> <pre><code>public var loader:URLLoader; public var file:File; public var data:XML; public var items:XMLList; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload