I am trying to let the user browse and select a file that I display but not 
save. 

For interim test purposes, the HTTPService uploads a file if it's name is 
already entered in 
the TextInput control when the btnSelect button is clicked. The XML displays 
properly in 
the taStatus TextArea. 

The problem is that I want to display the XML file that the user browses to, 
not the file 
entered in the TextInput. I have tried binding to the 'name' property of 
FileReference, but 
that doesn't go to the proper folder. 

There's no back-end script because I do NOT need to save the selected file to 
the server. I 
just need to show it and do some other stuff in another component. Or do I need 
a back-
end script just to tell flex where to locate the file that was browsed to?


Thanks!



<?xml version="1.0" encoding="utf-8"?>
<mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml"; height="289" y="0" 
width="656">
                
        <mx:Script>
                <![CDATA[

                        import mx.rpc.events.ResultEvent;
                        import mx.rpc.events.FaultEvent;
                        import flash.net.FileReference;

                        [Bindable]
                        private var file:FileReference = new FileReference;
                        
                        [Bindable]
                        private var dmrXML:XML = new XML; 
                
                        [Bindable]
                        private var message:String = "";
                        
                        [Bindable]
                        private var caseName:String = "";
                        
                        public function selectFile():void 
                        {
                                message = "";
                                taStatus.text = "";
                        file.addEventListener(Event.SELECT, selectHandler); 
                        file.browse();
                        }       

                        
                        public function selectHandler(event:Event):void
                        {
                                file = FileReference(event.target);
                                caseName = file.name;
                                fileHTTPService.send();
                        }
                        
            
                        public function completeHandler(e:ResultEvent):void 
                        {    
                                dmrXML = e.target.lastResult;
                                message = "The file is " + caseName + " by " + 
dmrXML.head.user + ", 
at " + dmrXML.head.saved + "\n\n";      
                                message += dmrXML + "\n\n";             // 
Display XML contents in user 
message box
                        }
             
             
                        public function faultHandler(event:Event):void 
                        {
                                message += "Your file could not be read!\n";   
//file_txt.text
                                }
                                
                ]]>
        </mx:Script>
        
                <mx:Button id="btnSelect" x="145" y="10" label="Select" 
click="selectFile()"/>   
        
                <mx:HTTPService id="fileHTTPService" url="{file_txt.text}" 
resultFormat="e4x" 
                        result="completeHandler(event)" 
fault="faultHandler(event)" />  
        
                        <mx:TextInput id="file_txt" x="145" y="51" 
width="271"/>    

                        <mx:Text x="10" y="10" text="Please select a file:" 
fontSize="12"/>
                        <mx:TextArea x="10" y="81" width="636" height="198" 
id="taStatus" 
text="{message}"/>
                        <mx:Label x="10" y="53" text="Or enter file name:"/>
        
</mx:Canvas>



Reply via email to