0 Replies Latest reply on Mar 1, 2010 10:43 PM by _willCrain

    dynamic url in httpservice (flex 3/AIR)

    _willCrain Level 1

      Hey everyone,
      I am trying to create an desktop app where the user selects an XML doc via a FileSystemTree. Then at the click of a button, that xml doc selected will be loaded in as the XML doc of choice. So far I have it working only if i hardcode in the path, but i need to make it so that the user can select the file dynamically.

       

      Thanks in advance for any help.

       


      [CODE]
      <?xml version="1.0" encoding="utf-8"?>
      <mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml"
             layout="vertical"
             width="520" height="400"
             verticalScrollPolicy="off"
             horizontalScrollPolicy="off"
             creationComplete = "initApp()" >

       

      <mx:Script> <![CDATA[           
          import mx.controls.Alert;          
          import mx.rpc.events.FaultEvent;
          import mx.rpc.events.ResultEvent;

       

          import mx.events.FileEvent;

       

          import mx.utils.UIDUtil;

       

          [Bindable]           
          public var _filePath:String;
         
          [Bindable]
          private var xData:XML;

       

          public function initApp():void {
             
          }
                private function onChooseFile(e:FileEvent):void {
              //trace("file name: " + e.file.nativePath);
              output.text = e.file.nativePath; 
              _filePath = String(e.file.nativePath);
              trace("_filePath = " + _filePath);
              this.convertBtn.visible=true;
          }
          private function resultHandler(event:ResultEvent):void {
              xData = event.result as XML;
              trace("XML Load Success");   
          }
          private function faultHandler(event:FaultEvent):void {
              Alert.show(event.fault.faultDetail, "Error");
          }

       

      </mx:Script>

       

      <mx:HTTPService id="srv" url="{_filePath}"       
             result="resultHandler(event)"       
             resultFormat="e4x"       
             fault="faultHandler(event)" />

       

      <mx:FileSystemTree
             width="400"
             showIcons="true"
             showExtensions="true"
              id="fileList"
             fileChoose="onChooseFile(event)"
             fontFamily="Verdana" fontSize="11"/>

       

      <mx:TextInput id="output" width="400" fontFamily="Arial" fontStyle="normal" fontWeight="bold"/>

       

      <mx:Button horizontalCenter="0" label="Convert XML for Proof" id="convertBtn" visible="false" click="srv.send()" />

      </mx:WindowedApplication>
      [/CODE]