1
我有一個TextArea和一個DataGrid。我已經使用目錄中的文本文件列表填充了DataGrid。現在我試圖將選定的文件加載到TextArea中。從列表中選擇一個文件時,我得到一個空指針異常,這告訴我我沒有正確訪問它......我想。Flex - 嘗試從列表中加載文本文件到TextArea
<s:TextArea id="mainTextField" x="0" y="0" width="730" height="523"
editable="true" enabled="true"/>
<s:DataGrid id="list" x="730" y="0" width="294" height="523" dataProvider="{files}" gridClick="listHandler(event)">
<s:columns>
<s:ArrayList>
<s:GridColumn dataField="name" headerText="Filename"/>
</s:ArrayList>
</s:columns>
</s:DataGrid>
...
private var files:ArrayCollection;
public var stream:FileStream = new FileStream(); // The FileStream object used for reading and writing the currentFile
public var currentFile:File;
private function init():void
{
// Default on start: resolve desktop directory
var desktop:File = File.desktopDirectory;
// Get desktop directory listing
files = new ArrayCollection(desktop.getDirectoryListing());
}
protected function listHandler(event:GridEvent):void
{
currentFile = event.target as File;
trace(currentFile.nativePath.toString()); **//Error occurrs here**
stream = new FileStream();
stream.openAsync(currentFile, FileMode.READ);
stream.addEventListener(Event.COMPLETE, fileReadHandler);
stream.addEventListener(IOErrorEvent.IO_ERROR, readIOErrorHandler);
}
public function fileReadHandler(event:Event):void
{
var str:String = stream.readUTFBytes(stream.bytesAvailable);
stream.close();
var lineEndPattern:RegExp = new RegExp(File.lineEnding, "g");
str = str.replace(lineEndPattern, "\n");
mainTextField.text = str;
stream.close();
}
這是第二個:)謝謝你這麼多! – RapsFan1981