·您当前的位置:首页 > 技术教程 > AS2与AS3技术 >

[AS3]as3中字幕滚动类源代码

时间:2016-06-14 22:33酷播
[AS3]as3中字幕滚动类源代码

[AS3]as3中字幕滚动类源代码

  1. package { 
  2. import flash.display.DisplayObjectContainer; 
  3. import flash.display.Shape; 
  4. import flash.display.Sprite; 
  5. import flash.events.MouseEvent; 
  6. import flash.events.TimerEvent; 
  7. import flash.text.TextField; 
  8. import flash.text.TextFieldAutoSize; 
  9. import flash.text.TextFormat; 
  10. import flash.utils.Timer; 
  11. /**** 
  12. * @by zou 
  13. * 2008-12-23 
  14. * ******/ 
  15. public class TestProject extends Sprite 
  16. { 
  17.    //滚动的文本 
  18.    private var _textField : TextField = new TextField(); 
  19.    //文本格式的控制 
  20.    private var _textFormat : TextFormat = new TextFormat(); 
  21.    //定时器初始化 
  22.    private var _timer : Timer; 
  23.    //储存文本的容器 
  24.    private var _sprite : Sprite = new Sprite(); 
  25.    //遮罩 
  26.    private var _shape :Shape = new Shape(); 
  27.    public function TestProject(time : uint=40) 
  28.    { 
  29. //    var rollText : RollText = new RollText(); 
  30. //    addChild(rollText); 
  31.    var _sprite1 : Sprite = new Sprite(); 
  32.    
  33.  
  34.     init(time); 
  35.     mangerListener(); 
  36.     
  37.     displayText(_sprite1,100,100,"梦境世界欢迎您的到来","H",100,100); 
  38.     
  39.     addChild(_sprite1); 
  40.     
  41.    } 
  42.    //代码集中控制 
  43.    private function init(time : uint) : void{ 
  44.     _timer = new Timer(time); 
  45.     _textField.mask=_shape ; 
  46.    } 
  47.    //监听集中管理 
  48.    private function mangerListener():void 
  49.    { 
  50.     _textField.addEventListener(MouseEvent.MOUSE_OVER,_textField_OVER); 
  51.     _textField.addEventListener(MouseEvent.MOUSE_OUT,_textField_OUT); 
  52.    } 
  53.    //鼠标滚动事件 
  54.    private function _textField_OVER(event : MouseEvent) : void{ 
  55.     _timer.stop(); 
  56.    } 
  57.    //鼠标滚过事件 
  58.    private function _textField_OUT(event : MouseEvent) : void{ 
  59.     _timer.start(); 
  60.    } 
  61.    //父类容器,滚动类型 
  62.    public function displayText(container : DisplayObjectContainer, 
  63.           width :uint,height : uint,text : String,type : String="H", 
  64.           x:Number=0,y:Number=0) : void{ 
  65.      //文本的格式控制      
  66.      _textField.defaultTextFormat=_textFormat; 
  67.      //将_sprite添加到父容器中 
  68.      container.addChild(_sprite); 
  69.      _sprite.x=x; 
  70.      _sprite.y=y; 
  71.      _sprite.addChild(_textField); 
  72.      _sprite.addChild(_shape); 
  73.      _shape.graphics.beginFill(0xFFCC00); 
  74.      _shape.graphics.drawRect(0,0,width,height); 
  75.      _shape.graphics.endFill(); 
  76.      _textField.text=text; 
  77.      if(type=="V"){ 
  78.      VRoll(); 
  79.      } else { 
  80.       HRoll(); 
  81.      } 
  82.     } 
  83.     //横向滚动 
  84.     private function HRoll() : void{ 
  85.     _textField.x=_shape.width; 
  86.     _textField.autoSize=TextFieldAutoSize.LEFT; 
  87.     _textField.y=0; 
  88.     _textField.multiline = false; 
  89.     _textField.wordWrap = false; 
  90.     _timer.addEventListener(TimerEvent.TIMER,Htimer_TIMER); 
  91.     _timer.start(); 
  92.     } 
  93.     private function Htimer_TIMER(event :TimerEvent) : void{ 
  94.     _textField.x-=1 ; 
  95.     if(_textField.x<=-_textField.width) { 
  96.        _textField.x=_shape.width; 
  97.     } 
  98.     } 
  99.     //cuplayer.com提示垂直滚动 
  100.     private function VRoll() : void { 
  101.     _textField.x=0; 
  102.     _textField.y=_shape.height; 
  103.     _textField.multiline = true; 
  104.     _textField.wordWrap = true; 
  105.     _textField.width=_sprite.width; 
  106.     _timer.addEventListener(TimerEvent.TIMER,Vtimer_TIMER); 
  107.     _timer.start(); 
  108.     } 
  109.     private function Vtimer_TIMER(event : TimerEvent) : void{ 
  110.     _textField.y-=1; 
  111.     if(_textField.y<-_textField.height){ 
  112.     _textField.y=_shape.height; 
  113.     } 
  114.     } 
  115.     //cuplayer.com提示文本控制,可选 
  116.     public function setTextFormat(color : uint=0x000000,bold : Boolean = false,size : uint=12, 
  117.              font : String="Times New Roman") : void{ 
  118.        _textFormat.color=color; 
  119.        _textFormat.bold=bold; 
  120.        _textFormat.size=size; 
  121.        _textFormat.font=font;        
  122.     } 
  123. } 
  124. } 

 

热门文章推荐

请稍候...

保利威视云平台-轻松实现点播直播视频应用

酷播云数据统计分析跨平台播放器