as3读取外部的txt文件,并实现滚动条
var external_txt:TextField = new TextField();//创建显示文本的文本框
var externalReq:URLRequest = new URLRequest("external.txt");
var externalLoad:URLLoader = new URLLoader();
externalLoad.load(externalReq);
externalLoad.addEventListener(Event.COMPLETE, textReady);
up_btn.addEventListener(MouseEvent.CLICK, scrollUp);//对滚动条按钮添加侦听
down_btn.addEventListener(MouseEvent.CLICK, scrollDown);
external_txt.x = 175;//设置文本框的属性
external_txt.y = 100;
external_txt.border = true;
external_txt.width = 200;
external_txt.height = 200;
external_txt.wordWrap = true;
addChild(external_txt);
function textReady(event:Event):void
{
external_txt.text = event.target.data;//将读取的文本数据,赋值给文本框
}
function scrollUp(event:MouseEvent):void
{
external_txt.scrollV --;//实现滚动
}
function scrollDown(event:MouseEvent):void
{
external_txt.scrollV ++;
}
效果图:
![as3读取外部的txt文件,并实现滚动条 - songyongge417 - songyongge41的个人主页](http://img.bimg.126.net/photo/H7LaNLWsSy9cCYKDqaKPMQ==/5742933949828191886.jpg)