zoukankan      html  css  js  c++  java
  • 自己写的一个字幕滚动类(方便调用)

    package {
    import flash.display.DisplayObjectContainer;
    import flash.display.Shape;
    import flash.display.Sprite;
    import flash.events.MouseEvent;
    import flash.events.TimerEvent;
    import flash.text.TextField;
    import flash.text.TextFieldAutoSize;
    import flash.text.TextFormat;
    import flash.utils.Timer;
    /****
    * @by zou
    * 2008-12-23
    * ******/
    public class TestProject extends Sprite
    {
       //滚动的文本
       private var _textField : TextField = new TextField();
       //文本格式的控制
       private var _textFormat : TextFormat = new TextFormat();
       //定时器初始化
       private var _timer : Timer;
       //储存文本的容器
       private var _sprite : Sprite = new Sprite();
       //遮罩
       private var _shape :Shape = new Shape();
       public function TestProject(time : uint=40)
       {
    //    var rollText : RollText = new RollText();
    //    addChild(rollText);
       var _sprite1 : Sprite = new Sprite();
      

        init(time);
        mangerListener();
       
        displayText(_sprite1,100,100,"梦境世界欢迎您的到来","H",100,100);
       
        addChild(_sprite1);
       
       }
       //代码集中控制
       private function init(time : uint) : void{
        _timer = new Timer(time);
        _textField.mask=_shape ;
       }
       //监听集中管理
       private function mangerListener():void
       {
        _textField.addEventListener(MouseEvent.MOUSE_OVER,_textField_OVER);
        _textField.addEventListener(MouseEvent.MOUSE_OUT,_textField_OUT);
       }
       //鼠标滚动事件
       private function _textField_OVER(event : MouseEvent) : void{
        _timer.stop();
       }
       //鼠标滚过事件
       private function _textField_OUT(event : MouseEvent) : void{
        _timer.start();
       }
       //父类容器,滚动类型
       public function displayText(container : DisplayObjectContainer,
              width :uint,height : uint,text : String,type : String="H",
              x:Number=0,y:Number=0) : void{
         //文本的格式控制     
         _textField.defaultTextFormat=_textFormat;
         //将_sprite添加到父容器中
         container.addChild(_sprite);
         _sprite.x=x;
         _sprite.y=y;
         _sprite.addChild(_textField);
         _sprite.addChild(_shape);
         _shape.graphics.beginFill(0xFFCC00);
         _shape.graphics.drawRect(0,0,width,height);
         _shape.graphics.endFill();
         _textField.text=text;
         if(type=="V"){
         VRoll();
         } else {
          HRoll();
         }
        }
        //横向滚动
        private function HRoll() : void{
        _textField.x=_shape.width;
        _textField.autoSize=TextFieldAutoSize.LEFT;
        _textField.y=0;
        _textField.multiline = false;
        _textField.wordWrap = false;
        _timer.addEventListener(TimerEvent.TIMER,Htimer_TIMER);
        _timer.start();
        }
        private function Htimer_TIMER(event :TimerEvent) : void{
        _textField.x-=1 ;
        if(_textField.x<=-_textField.width) {
           _textField.x=_shape.width;
        }
        }
        //垂直滚动
        private function VRoll() : void {
        _textField.x=0;
        _textField.y=_shape.height;
        _textField.multiline = true;
        _textField.wordWrap = true;
        _textField.width=_sprite.width;
        _timer.addEventListener(TimerEvent.TIMER,Vtimer_TIMER);
        _timer.start();
        }
        private function Vtimer_TIMER(event : TimerEvent) : void{
        _textField.y-=1;
        if(_textField.y<-_textField.height){
        _textField.y=_shape.height;
        }
        }
        //文本控制,可选
        public function setTextFormat(color : uint=0x000000,bold : Boolean = false,size : uint=12,
                 font : String="Times New Roman") : void{
           _textFormat.color=color;
           _textFormat.bold=bold;
           _textFormat.size=size;
           _textFormat.font=font;       
        }
    }
    }
  • 相关阅读:
    Robot Framework--06 用户关键字User Keyword
    Robot Framework--05 案例设计之流程与数据分离
    Robot Framework--04 工作区
    Robot Framework--03 案例及资源区
    Robot Framework--02 菜单栏&工具栏
    Robot Framework--01 创建简单工程示例
    uoj#35 后缀排序(后缀数组模版)
    【学习笔记】动态树Link-Cut-Tree
    【随意学学】三分法
    【学习笔记】dsu on tree
  • 原文地址:https://www.cnblogs.com/top5/p/1667796.html
Copyright © 2011-2022 走看看