Flex读文本文件

时间:2022-01-30 04:45:45

布局:

 <s:Group id="maskGroup" width="" height="" x="" y="">
<s:Rect width="100%" height="100%">
<s:fill>
<s:SolidColor color="#000000"/>
</s:fill>
</s:Rect>
</s:Group>
 <mx:Canvas x="" y="" width="" height="" backgroundColor="#5976A4"
horizontalScrollPolicy="off" verticalScrollPolicy="off">
<s:Scroller id="scrollerId" width="100%" height="100%"
horizontalScrollPolicy="off" interactionMode="touch"
skinClass="skin.libraryIntroduce.ScrollerSkin">
<s:Group x="" y="" width="" height="">
<s:Label id="introTxt" x="" y="" width="" color="#FFFFFF" fontFamily="微软雅黑"
fontSize="" textAlign="left" verticalAlign="top"
mask="{maskGroup}"/>
</s:Group>
</s:Scroller>
</mx:Canvas>

AS:

var file:File=new File("文本文件的绝对路径");
if(file2.exists)
{
var fileStream:FileStream=new FileStream();
fileStream.open(file,FileMode.READ);
//算高度仅供参考
introTxt.height=(Math.floor(Number(fileStream.bytesAvailable/))+)*;
introTxt.text=fileStream.readMultiByte(fileStream.bytesAvailable,"gbk");
trace(introTxt.height);
scrollerId.verticalScrollBar.value=;
}