Flex读文本文件

布局:

1 <s:Group id="maskGroup" width="503" height="332" x="657" y="165">
2         <s:Rect width="100%" height="100%">
3             <s:fill>
4                 <s:SolidColor color="#000000"/>
5             </s:fill>
6         </s:Rect>
7     </s:Group>

 

 1 <mx:Canvas x="626" y="151" width="565" height="360" backgroundColor="#5976A4"
 2                horizontalScrollPolicy="off" verticalScrollPolicy="off">
 3         <s:Scroller id="scrollerId" width="100%" height="100%"
 4                     horizontalScrollPolicy="off" interactionMode="touch"
 5                     skinClass="skin.libraryIntroduce.ScrollerSkin">
 6             <s:Group x="0" y="0" width="565" height="360">
 7                 <s:Label id="introTxt" x="31" y="14" width="503" color="#FFFFFF" fontFamily="微软雅黑"
 8                          fontSize="20" textAlign="left" verticalAlign="top"
 9                          mask="{maskGroup}"/>
10             </s:Group>
11         </s:Scroller>
12     </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/45))+5)*30;
                        introTxt.text=fileStream.readMultiByte(fileStream.bytesAvailable,"gbk");
                        trace(introTxt.height);
                        scrollerId.verticalScrollBar.value=0;
                    }

 

posted @ 2014-10-13 10:43  dongyl  Views(320)  Comments(0Edit  收藏  举报