`

Flex创建文本并写入信息

    博客分类:
  • Flex
阅读更多

Flex创建文本并写入信息的例子如下:

<?xml version="1.0" encoding="utf-8"?>
<mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml" 
	layout="horizontal" fontSize="12"
    creationComplete="getStudentInfo('helloworld')">
    
    <mx:Script>
    	<![CDATA[
    	        import mx.controls.Alert;
    		import flash.filesystem.File;
    		import flash.filesystem.FileMode;
    		import flash.filesystem.FileStream;
    		
    		private function getStudentInfo(str:String):void{
    			/*File.applicationDirectory.nativePath的值是:
    			     C:\Documents and Settings\a\My Documents\Flex Builder 3\readTxtDemo\bin-debug
    			*/
                var file:File = new File("D:\\dataTest\\student.txt");    //若没有此文件就创建它
                var stream:FileStream = new FileStream();    //创建FileStream对象
                stream.open(file, FileMode.WRITE);    //使用FileStream对象以只读方式打开File对象
                stream.writeUTFBytes(str);
                stream.close();    //关闭FileStream对象
            }
    	]]>
    </mx:Script>
    
    <mx:Panel title="从文件中读取数据" verticalAlign="middle" horizontalAlign ="center" width="90%" height="90%">
        <mx:TextArea id="txtTextAreaID"  width="300" height="200" borderColor="#FF0000" borderThickness="5"/>
    </mx:Panel>
    
</mx:WindowedApplication>


 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics