AS3.0实现文字滚动效果

来源:互联网 发布:淘宝抢单神器 编辑:程序博客网 时间:2024/04/29 11:34
package ch13_1{import flash.display.MovieClip;import flash.events.Event;import flash.events.MouseEvent;import flash.filters.GlowFilter;import flash.text.TextField;import flash.text.TextFormat;public class RollText extends MovieClip{var contents:String;var whiteSpace:String;var tftxt:String;var isPause:Boolean =false;var tf:TextField = new TextField();var f:TextFormat= new TextFormat();public function RollText(){stage.frameRate =10;tf.autoSize ="left";f.size =40;f.color =0xFFFFFF;f.font="楷体";tf.defaultTextFormat =f;tf.width =stage.stageWidth;tf.y =180;addChild(tf);initApp();stage.addEventListener(MouseEvent.CLICK,restart);}private  function initApp():void{tf.addEventListener(Event.ENTER_FRAME,scrollText);whiteSpace="";contents ="秦时明月汉时关,万里长征人未还。"+"但使龙城飞将在,不教胡马渡阴山。";for(var i:uint =0;i<550/40+1;i++){whiteSpace+="  ";}tftxt =whiteSpace+contents;tf.text=tftxt;}private  function restart(e:MouseEvent):void{if(e.target==e.currentTarget){if(tf.text=="")initApp();else     isPause = !isPause;}}private function scrollText(e:Event):void{if(!isPause){tftxt=tftxt.substring(1);tf.text =tftxt;if(tf.text==""){tf.removeEventListener(Event.ENTER_FRAME,scrollText);}tf.filters  = [new GlowFilter(0x0055FF,1,6,6,6)];}}}}