I may be wrong but that could be BOM? If you use writeUTF() and open the resulting file in a Unicode editor do you still see it?

Kenneth Kawamoto
http://www.materiaprima.co.uk/

Cheetham, Marcus wrote:
I'm using fileStream to save a text file. This works OK, but introduces
some strange characters at the beginning of the saved text.
I'm saving XML data. I've kept this as an XML object and also converted
it to string -- same thing always happens.
Any idea how I can get rid of these characters? Thanks, This is what I end up with (note the 'g at the beginning) : 'g<order>
  <item id="1">
    <menuName>burger</menuName>
    <price>3.95</price>
  </item>
  <item id="2">
    <menuName>fries</menuName>
    <price>1.45</price>
  </item>
</order>
This is the Flex 3 code:
<?xml version="1.0" encoding="utf-8"?>
<mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml";
layout="absolute" activate="createXML()">
<mx:Script>
 <![CDATA[
  import flash.events.Event;
  import flash.filesystem.*;
public function createXML():void {
   x1 = <order>
          <!--This is a comment. -->
          <?PROC_INSTR sample ?>
          <item id='1'>
             <menuName>burger</menuName>
              <price>3.95</price>
          </item>
          <item id='2'>
              <menuName>fries</menuName>
              <price>1.45</price>
          </item>
      </order>
  }
public var file:File; public function saveToFile() :void
  {
   file = new File("/filename.xml");
   file.addEventListener(Event.SELECT, dirSelected);
   file.browseForSave('');
  }
public function dirSelected(e:Event) :void
  {
   // this object will get saved to the file
   var dat:String = new String;
   var str:String = new String;
   str = x1.toXMLString();
   dat = str;
   var fileStream:FileStream = new FileStream();
   fileStream.open(file, FileMode.WRITE);
   fileStream.writeObject(dat);
   fileStream.close();
  }
]]>
</mx:Script>
<mx:Button x="102" y="320" label="Save XML" click="saveToFile()"/>
 <mx:XML id="x1" format="e4x"/>
</mx:WindowedApplication>
_______________________________________________
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Reply via email to