Flash/Flex学习笔记(28):动态文本的滚动控制

虽然label组件很好用,但是达人们都好象不太喜欢用组件(用组件后最明显的问题:会使swf文件增大好多),所以我也慢慢开始习惯能不用组件则尽量不用

view source

print?

01
import flash.events.Event;

02
import flash.events.MouseEvent;

03

04
var flag:int = 0;

05

06
txtMsg.text = "这是一首很好听的歌:Going Home\nnot very often have we met \nbut the musics been too bad \ncan only sense happiness\nif the music is sad\nso, im going home \ni must hurry home\nwhere a life goes on \nwere too old to make a mess\ndreams will keep me young\nold enough to stress\nonly mirrors tell the time\nso, im going home\ni must hurry home\nso will my life go on\nyes, im going home \ngoing home alone \nand your life goes on\n菩提树下的杨过";

07
txtMsg.background = true;

08
txtMsg.border = true;

09
txtMsg.borderColor = 0x000000;

10
txtMsg.backgroundColor = 0xffff99;

11

12
btnUp.addEventListener(MouseEvent.ROLL_OVER,function(){flag=1});

13
btnDown.addEventListener(MouseEvent.ROLL_OVER,function(){flag=-1});

14

15
btnUp.addEventListener(MouseEvent.ROLL_OUT,ResetFlag);

16
btnDown.addEventListener(MouseEvent.ROLL_OUT,ResetFlag);

17

18

19
function ResetFlag(e:MouseEvent):void{

20
flag = 0;

21
}

22

23
addEventListener(Event.ENTER_FRAME,EnterFrameHandler);

24

25
function EnterFrameHandler(e:Event):void {

26
if (flag == 1) {

27
txtMsg.scrollV--;

28
}

29
else if (flag==-1) {

30
txtMsg.scrollV++;

31
}

32
}

注:txtMsg为舞台上的动态文本,二个按钮是从公共库里拉出来的实例

源文件:http://cid-2959920b8267aaca.skydrive.live.com/self.aspx/Flash/txtScroll.rar

原文地址:https://www.cnblogs.com/happysky97/p/1884552.html