import flash.events.IOErrorEvent; import mx.collections.*; import flash.events.Event; import flash.net.FileFilter; import flash.net.FileReference; import flash.utils.ByteArray; private var fileRef:FileReference //File types which we want the user to open private static const FILE_TYPES:Array = [new FileFilter("Text File", "*.txt;*.text")]; private function doLoad():void{ fileRef = new FileReference(); //listen for when they select a file fileRef.addEventListener(Event.SELECT, onFileSelect); //listen for when then cancel out of the browse dialog fileRef.addEventListener(Event.CANCEL,onCancel); //open a native browse dialog that filters for text files fileRef.browse(FILE_TYPES); } /************ Browse Event Handlers **************/ //called when the user selects a file from the browse dialog private function onFileSelect(e:Event):void { //listen for when the file has loaded fileRef.addEventListener(Event.COMPLETE, onLoadComplete); //listen for any errors reading the file fileRef.addEventListener(IOErrorEvent.IO_ERROR, onLoadError); //load the content of the file fileRef.load(); } //called when the user cancels out of the browser dialog private function onCancel(e:Event):void { trace("File Browse Canceled"); fileRef = null; } /************ Select Event Handlers **************/ //called when the file has completed loading private function onLoadComplete(e:Event):void { //get the data from the file as a ByteArray var data:ByteArray = fileRef.data; var result:String = new String(fileRef.data); var record:Array = new Array(); var obj:Object; record = result.split(""); for (var i:int = 0; i< record.length; i++){ obj = new Object(); obj.street = record; addressDataImported.addItem(obj); } // addressDataImported.addItem({street:"test street"}); //read the bytes of the file as a string and put it in the //textarea //outputField.text = data.readUTFBytes(data.bytesAvailable); //clean up the FileReference instance fileRef = null; } //called if an error occurs while loading the file contents private function onLoadError(e:IOErrorEvent):void { trace("Error loading file : " + e.text); }
<mx:DataGrid id="dg1" dataProvider="{addressDataImported}" scroll="true" width="100%" height="150" itemClick="onItemClick(event)" itemRollOver="onItemRollOver(event)" itemRollOut="onItemRollOut(event)"> <mx:columns> <mx:DataGridColumn dataField="street" headerText="Street" width="55"/> </mx:columns> </mx:DataGrid>
Angemeldete Mitglieder können Beiträge verfassen, Updates folgen und mehr. Neu hier? Registriere ein kostenloses Konto.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.