Changeset 1645


Ignore:
Timestamp:
03/14/11 12:13:19 (2 years ago)
Author:
jeroen
Message:

added better outlining and a textselect disabler

Location:
plugins/captions
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • plugins/captions/v5/src/com/longtailvideo/plugins/captions/Captions.as

    r1593 r1645  
    1717 
    1818 
    19         /** 
    20         * Plugin for playing closed captions with a video. 
    21         **/ 
     19        /** Plugin for playing closed captions with a video. **/ 
    2220        public class Captions extends MovieClip implements IPlugin { 
    2321 
     
    2927 
    3028 
    31         /** Reference to the background graphic. **/ 
    32         private var _back:MovieClip; 
    3329        /* Reference to the bar (container for field & back)*/ 
    34         private var _bar:MovieClip; 
     30        private var _bar:Sprite; 
    3531        /** Reference to the controlbar button. **/ 
    3632        private var _button:MovieClip; 
     33        /** Reference to the controlbar button icon **/ 
     34        private var _buttonIcon:DisplayObject; 
    3735        /** The array the captions are loaded into. **/ 
    3836        private var _captions:Array; 
     
    5553        /** Reference to the dock icon. **/ 
    5654        private var _icon:MovieClip; 
    57         /** Reference to the controlbar button icon **/ 
    58         private var _buttonIcon:DisplayObject; 
    5955        /** XML connect and parse object. **/ 
    6056        private var _loader:URLLoader; 
     57        /** Reference to the outline graphic. **/ 
     58        private var _outline:Sprite; 
    6159        /* Reference to the JW Player. */ 
    6260        private var _player:IPlayer; 
     
    8482        /** Draw the neccessary graphics to put the captions on stage. **/ 
    8583        private function drawClip():void { 
    86                 _bar = new MovieClip(); 
     84                _bar = new Sprite(); 
    8785                addChild(_bar); 
    88                 _back = new MovieClip(); 
    89                 _back.graphics.beginFill(0x0000,0.75); 
    90                 _back.graphics.drawRect(0,0,400,20); 
    91                 _bar.addChild(_back); 
     86                _outline = new Sprite(); 
     87                _bar.addChild(_outline); 
    9288                _field = new TextField(); 
    9389                _field.width = 400; 
    9490                _field.height = 10; 
    95                 _field.y = 5; 
    9691                _field.autoSize = "center"; 
    9792                _field.multiline = true; 
     93                _field.selectable = false; 
    9894                _field.wordWrap = true; 
    9995                var fmt:TextFormat = new TextFormat(); 
     
    10298                fmt.align = "center"; 
    10399                fmt.font = "_sans"; 
    104                 fmt.leading = 4; 
     100                fmt.leading = 5; 
    105101                _field.defaultTextFormat = fmt; 
    106102                _bar.addChild(_field); 
    107103                if (!_config['back']) { 
    108                         _back.alpha = 0; 
    109104                        _field.filters = new Array(new DropShadowFilter(0,45,0,1,2,2,10,3)); 
     105                        _outline.alpha = 0; 
    110106                } 
    111107        }; 
     
    217213        /** Resize this plugin */ 
    218214        public function resize(w:Number, h:Number):void { 
    219                 _back.height = _field.height + 10; 
    220215                _bar.width = w; 
    221216                _bar.scaleY = _bar.scaleX; 
     
    223218                        _bar.y = h - _bar.height - 50; 
    224219                } else { 
    225                         _bar.y = h - _bar.height; 
    226                 } 
    227                 //_bar.visible = _config['state']; 
     220                        _bar.y = h - _bar.height - 10; 
     221                } 
    228222        }; 
    229223 
     
    239233                        _field.htmlText = text; 
    240234                } 
    241                 if(_config['back'] && text != '') { 
    242                         _back.alpha = 1; 
    243                 } else { 
    244                         _back.alpha = 0; 
    245                 } 
     235                setOutline(); 
    246236                resize(_player.config['width'], _player.config['height']); 
    247237        }; 
     238 
     239 
     240    /** Draw the black boxes around the textlines. **/ 
     241    private function setOutline():void { 
     242        _outline.graphics.clear(); 
     243        for (var i:Number=0; i < _field.numLines; i++) { 
     244            var metrics:TextLineMetrics = _field.getLineMetrics(i); 
     245            if(metrics.width > 16) { 
     246                _outline.graphics.beginFill(0x000000); 
     247                _outline.graphics.drawRect( 
     248                    metrics.x - 8, 
     249                    i*metrics.height, 
     250                    metrics.width + 16, 
     251                    metrics.height 
     252                ); 
     253                _outline.graphics.endFill(); 
     254            } 
     255        } 
     256    }; 
    248257 
    249258 
Note: See TracChangeset for help on using the changeset viewer.