Muzak,

Is this also possible from Flash??
And if so: How?

Kind regards
Cor

-----Original Message-----
From: [email protected] 
[mailto:[email protected]] On Behalf Of Muzak
Sent: vrijdag 3 juli 2009 14:48
To: Flash Coders List
Subject: Re: [Flashcoders] Strange characters added to file when saving 
fromFlex/AIR using fileStream

Use FileStream.writeUTFBytes()

    var xml:XML = <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>;

    var str:String = '<?xml version="1.0" encoding="UTF-8?>' + File.lineEnding;
    str += xml.toXMLString();

    var fs:FileStream = new FileStream();
    fs.open(outputFile, FileMode.WRITE);
    fs.writeUTFBytes(str);
    fs.close();

regards,
Muzak

----- Original Message ----- 
From: "Cheetham, Marcus" <[email protected]>
To: "Flash Coders List" <[email protected]>
Sent: Friday, July 03, 2009 12:39 PM
Subject: [Flashcoders] Strange characters added to file when saving 
fromFlex/AIR using fileStream


> 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 first -- same thing always happens.
>
> Any idea how I can get rid of these characters?
>
> Thanks, Marcus.
>
> 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>
>
>
>
>
>
>
> This email was sent by a company owned by Pearson plc, registered office at 
> 80 Strand, London WC2R 0RL.
> Registered in England and Wales with company number 53723
>
> _______________________________________________
> Flashcoders mailing list
> [email protected]
> http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
> 

_______________________________________________
Flashcoders mailing list
[email protected]
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


_______________________________________________
Flashcoders mailing list
[email protected]
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Reply via email to