虽然label组件很好用,但是达人们都好象不太喜欢用组件(用组件后最明显的问题:会使swf文件增大好多),所以我也慢慢开始习惯能不用组件则尽量不用
import flash.events.Event; import flash.events.MouseEvent; var flag:int = 0; 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菩提树下的杨过"; txtMsg.background = true; txtMsg.border = true; txtMsg.borderColor = 0x000000; txtMsg.backgroundColor = 0xffff99; btnUp.addEventListener(MouseEvent.ROLL_OVER,function(){flag=1}); btnDown.addEventListener(MouseEvent.ROLL_OVER,function(){flag=-1}); btnUp.addEventListener(MouseEvent.ROLL_OUT,ResetFlag); btnDown.addEventListener(MouseEvent.ROLL_OUT,ResetFlag); function ResetFlag(e:MouseEvent):void{ flag = 0; } addEventListener(Event.ENTER_FRAME,EnterFrameHandler); function EnterFrameHandler(e:Event):void { if (flag == 1) { txtMsg.scrollV--; } else if (flag==-1) { txtMsg.scrollV++; } }
注:txtMsg为舞台上的动态文本,二个按钮是从公共库里拉出来的实例
源文件:http://cid-2959920b8267aaca.skydrive.live.com/self.aspx/Flash/txtScroll.rar