Tuesday, March 29, 2011

Flex Write To File

Can Flex Write To File?

What do You Think?

The answer is - YES

Below is the Code snippet

<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
               xmlns:s="library://ns.adobe.com/flex/spark"
               xmlns:mx="library://ns.adobe.com/flex/mx"
               minWidth="400"
               minHeight="300">

    <fx:Script>
        <![CDATA[
            protected function button1_clickHandler(event:MouseEvent):void
            {
                var fr:FileReference=new FileReference();
                var xml:String='<level>I am writting XML File out</level>';
                var ba:ByteArray=new ByteArray();
                ba.writeMultiByte(xml, 'utf-8');
                fr.save(ba, "myXML.xml");
            }
        ]]>
    </fx:Script>

    <fx:Declarations>
        <!-- Place non-visual elements (e.g., services, value objects) here -->
    </fx:Declarations>
    <s:Button label="Write Out"
              horizontalCenter="0"
              verticalCenter="0"
              height="30"
              width="100"
              click="button1_clickHandler(event)"/>
</s:Application>

You can Download the code: http://www.bestwebpartners.com/BlogData/WriteToClientDisk.mxml

No comments:

Post a Comment