3 Replies Latest reply on Aug 21, 2009 1:36 AM by c_luckett

    Create XML file dynamically from textInput fields

    c_luckett

      Hi,

       

      I'm very new to Flex and trying to create an application that creates XML files on the users' local computer, based on a users input into textInput fields.

       

      At the moment I'm having trouble finding how to dyamically create an external XML file at all, ideally when the user pushes a button a browseForSave dialog box will open allowing the user to select somewhere on their hard drive to create the XML file.

       

      Can anyone give me a hint what direction I should be heading in?

       

      Thanks

        • 1. Re: Create XML file dynamically from textInput fields
          kkc_mca Level 2

          flex application cannot access the local resources

          your will get a sandbox violation

           

          check shared object concept

           

          if this post answers your question or help. Please mark it as such

          1 person found this helpful
          • 2. Re: Create XML file dynamically from textInput fields
            Gregory Lafrance Level 6

            If this post answered your question or helped, please mark it as such.

             

            You could use a SharedObject for small files, but in general Flex does not have access to the local hard drive.

             

            <?xml version="1.0"?>
            <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
              initialize="init()">
              <mx:Script>
                <![CDATA[
                  public var mySO:SharedObject;
                 
                  public function init():void{
                    mySO = SharedObject.getLocal("mydata");
                    if(mySO.data.myData!=null){
                      var xml:XML = mySO.data.myData;
                      fname.text = xml.fname;
                      lname.text = xml.lname;
                      email.text = xml.email;
                    }
                  }

                  private function storeData():void{
                    var xml:XML =
                      <data/>;
                    if(fname.text != ""){
                      xml.appendChild(<fname>{fname.text}</fname>);
                    }
                    if(lname.text != ""){
                      xml.appendChild(<lname>{lname.text}</lname>);
                    }
                    if(email.text != ""){
                      xml.appendChild(<email>{email.text}</email>);
                    }
                    mySO.data.myData = xml;
                    mySO.flush();
                  }
             
                  private function resetData():void{
                    mySO.clear();
                    fname.text = "";
                    lname.text = ""
                    email.text = "";
                  }
                ]]>
              </mx:Script>
              <mx:Form>
                <mx:FormItem label="First Name:">
                  <mx:TextInput id="fname"/>
                </mx:FormItem>
                <mx:FormItem label="Last Name:">
                  <mx:TextInput id="lname"/>
                </mx:FormItem>
                <mx:FormItem label="Email:">
                  <mx:TextInput id="email"/>
                </mx:FormItem>
              </mx:Form>
              <mx:Button label="Store Data" click="storeData()"/>
              <mx:Button label="Reload Stored Data" click="init()"/>
              <mx:Button label="Delete Stored Data" click="resetData()"/>
            </mx:Application>

            • 3. Re: Create XML file dynamically from textInput fields
              c_luckett Level 1

              Cheers guys,

               

              That'll be why I'm not finding any similar examples, i'll try looking at some other language!