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

 

热门文章推荐

请稍候...

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

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