source: trunk/fl5/src/com/longtailvideo/jwplayer/view/components/DockButton.as @ 579

Revision 579, 3.5 KB checked in by pablo, 4 years ago (diff)

Dock Buttons with no player color defaults threw an error

Line 
1/**
2 * A button from within the dock.
3 **/
4package com.longtailvideo.jwplayer.view.components {
5        import com.longtailvideo.jwplayer.model.Color;
6       
7        import flash.display.*;
8        import flash.events.*;
9        import flash.geom.ColorTransform;
10        import flash.text.TextField;
11        import flash.text.TextFormat;
12        import flash.text.TextFormatAlign;
13       
14       
15        public class DockButton extends ComponentButton {
16                /** Reference to the text field **/
17                protected var _text:TextField;
18                /** Asset color **/
19                protected var _assetColor:Color;
20                /** Whether skin contains a background **/
21                private var _drawBackground:Boolean;
22               
23               
24                /** Constructor **/
25                public function DockButton():void {
26                        _text = new TextField();
27                        _text.x = 0;
28                        _text.y = 30;
29                        _text.width = 50;
30                        _text.height = 20;
31                }
32               
33               
34                /** Sets up the button **/
35                public override function init():void {
36                        if (!_background){
37                                _drawBackground = true;
38                                _background = new Sprite();
39                                drawBackground(_background as Sprite, _outColor);
40                        }
41                        _background.transform.colorTransform = createColorTransform(_outColor);
42                        super.init();
43                        _imageLayer.addChild(_text);
44                        _assetColor = _assetColor ? _assetColor : new Color(0xFFFFFF);
45                        _outIcon.transform.colorTransform = createColorTransform(_assetColor);
46                        _text.textColor = _assetColor.color;
47                        mouseChildren = false;
48                        buttonMode = true;
49                }
50               
51               
52                protected function createColorTransform(color:Color):ColorTransform {
53                        var colorTransform:ColorTransform = new ColorTransform();
54                        if (color) colorTransform.color = color.color;
55                        return colorTransform;
56                }
57               
58                /** When rolling over, the background is color changed. **/
59                protected override function overHandler(evt:MouseEvent):void {
60                        if (_drawBackground) {
61                                drawBackground(_background as Sprite, _overColor);
62                        } else {
63                                _background.transform.colorTransform = createColorTransform(_overColor);
64                        }
65                }
66               
67               
68                /** When rolling over, the background is color changed. **/
69                protected override function outHandler(evt:MouseEvent):void {
70                        if (_drawBackground) {
71                                drawBackground(_background as Sprite, _outColor);
72                        } else {
73                                _background.transform.colorTransform = createColorTransform(_outColor);
74                        }
75                }
76               
77                protected override function clickHandler(evt:MouseEvent):void {
78                        super.clickHandler(evt);
79                        centerText();
80                }
81               
82               
83                /** Draws the dock icon background **/
84                private function drawBackground(backgroundSprite:Sprite, color:Color):void {
85                        backgroundSprite.graphics.clear();
86                        backgroundSprite.graphics.beginFill(color ? color.color : 0x000000, 0.55);
87                        backgroundSprite.graphics.drawRect(0, 0, 50, 50);
88                        backgroundSprite.graphics.endFill();
89                        updateClickLayer();
90                }
91               
92               
93                public function set text(text:String):void {
94                        _text.text = text;
95                        centerText();
96                }
97               
98                public function centerText():void {
99                        var textFormat:TextFormat = new TextFormat();
100                        textFormat.align = TextFormatAlign.CENTER;
101                        textFormat.font = "_sans";
102                        textFormat.size = 11;
103                        _text.setTextFormat(textFormat);
104                }
105               
106                protected override function centerIcon(icon:DisplayObject):void {
107                        if (icon) {
108                                if (_background) {
109                                        icon.x = (_background.width - icon.width) / 2;
110                                        icon.y = (_background.height - icon.height * 1.5) / 2;
111                                } else {
112                                        icon.x = 0;
113                                        icon.y = 0;
114                                }
115                        }
116                }
117               
118                public function set assetColor(assetColor:Color):void {
119                        _assetColor = assetColor;
120                }
121               
122                /** Legacy support**/           
123                public function get field():TextField {
124                        return _text;
125                }
126        }
127}
Note: See TracBrowser for help on using the repository browser.