source: trunk/fl5/src/com/longtailvideo/jwplayer/view/components/DockComponent.as @ 594

Revision 594, 4.3 KB checked in by zach, 4 years ago (diff)
  • PNG Playlist and Dock no longer colorize
  • PNG Playlist is using correctly named elements
  • Removing clone method from BaseSkin
Line 
1package com.longtailvideo.jwplayer.view.components {
2        import com.longtailvideo.jwplayer.events.PlayerStateEvent;
3        import com.longtailvideo.jwplayer.player.IPlayer;
4        import com.longtailvideo.jwplayer.player.PlayerState;
5        import com.longtailvideo.jwplayer.utils.Animations;
6        import com.longtailvideo.jwplayer.utils.RootReference;
7        import com.longtailvideo.jwplayer.view.interfaces.IDockComponent;
8        import com.longtailvideo.jwplayer.view.skins.SWFSkin;
9       
10        import flash.display.DisplayObject;
11        import flash.display.MovieClip;
12        import flash.display.Sprite;
13        import flash.events.MouseEvent;
14        import flash.utils.clearTimeout;
15        import flash.utils.setTimeout;
16       
17       
18        public class DockComponent extends CoreComponent implements IDockComponent {
19                /** Default configuration vars for this plugin. **/
20                public var defaults:Object = {
21                                align: 'right'
22                        };
23                /** Object with all the buttons in the dock. **/
24                private var buttons:Array;
25                /** Timeout for hiding the buttons when the video plays. **/
26                private var timeout:Number;
27                /** Reference to the animations handler **/
28                private var animations:Animations;
29               
30                public function DockComponent(player:IPlayer) {
31                        super(player, "dock");
32                        animations = new Animations(this);
33                        buttons = new Array();
34                        if (player.config.dock) {
35                                player.addEventListener(PlayerStateEvent.JWPLAYER_PLAYER_STATE, stateHandler);
36                                RootReference.stage.addEventListener(MouseEvent.MOUSE_MOVE, moveHandler);
37                        } else {
38                                visible = false;
39                        }
40                }
41               
42               
43                public function addButton(icon:DisplayObject, text:String, clickHandler:Function, name:String = null):MovieClip {
44                        var button:DockButton = new DockButton();
45                        if (name){
46                                button.name = name;
47                        }
48                        if (_player.skin is SWFSkin) {
49                                button.colorize = true;
50                        }
51                        button.setOutIcon(icon);
52                        button.outBackground = getSkinElement("button") as Sprite;
53                        button.overBackground = getSkinElement("buttonOver") as Sprite;
54                        button.assetColor = player.config.backcolor;
55                        button.outColor = player.config.frontcolor;
56                        button.overColor = player.config.lightcolor;
57                        button.clickFunction = clickHandler;
58                        button.init();
59                        button.text = text;
60                        addChild(button);
61                        buttons.push(button);
62                        resize(width, height);
63                        return button;
64                }
65               
66               
67                public function removeButton(name:String):void {
68                        try {
69                                removeChild(getChildByName(name));
70                        } catch (err:Error) {
71                        }
72                }
73               
74               
75                public function resize(width:Number, height:Number):void {
76                        var margin:Number = 10;
77                        var usedHeight:Number = margin;
78                        var direction:Number = 1;
79                        if (getConfigParam('position') != 'left') {
80                                direction = -1;
81                        }
82                        for (var i:Number = 0; i < buttons.length; i++) {
83                                var row:Number = Math.floor(usedHeight / height);
84                                if ((usedHeight + buttons[i].height + margin) > ((row + 1) * height)){
85                                        usedHeight = ((row + 1) * height) + margin;
86                                        row = Math.floor(usedHeight / height);
87                                }
88                                buttons[i].y = usedHeight % height;
89                                buttons[i].x = (buttons[i].width + margin) * row * direction;
90                                usedHeight += buttons[i].height + margin;
91                                (buttons[i] as DockButton).centerText();
92                        }
93                        setConfigParam('y', player.controls.display.y);
94                        if (getConfigParam('position') == 'left') {
95                                setConfigParam('x', player.controls.display.x + margin);
96                        } else {
97                                // No need to subtract the width: all of the positions are negative
98                                if (buttons.length > 0){
99                                        setConfigParam('x', player.controls.display.x + player.controls.display.width - buttons[0].width - margin);
100                                }
101                        }
102                }
103               
104               
105                /** Show the buttons on mousemove. **/
106                private function moveHandler(evt:MouseEvent = null):void {
107                        clearTimeout(timeout);
108                        if (player.state == PlayerState.BUFFERING || player.state == PlayerState.PLAYING) {
109                                timeout = setTimeout(moveTimeout, 2000);
110                                if (alpha < 1) {
111                                        animations.fade(1);
112                                }
113                        }
114                }
115               
116               
117                /** Hide the buttons again when move has timed out. **/
118                private function moveTimeout():void {
119                        animations.fade(0);
120                }
121               
122               
123                /** Process state changes **/
124                private function stateHandler(evt:PlayerStateEvent = undefined):void {
125                        switch (player.state) {
126                                case PlayerState.PLAYING:
127                                case PlayerState.BUFFERING:
128                                        moveHandler();
129                                        break;
130                                default:
131                                        clearTimeout(timeout);
132                                        animations.fade(1);
133                                        break;
134                        }
135                }
136        }
137}
138
Note: See TracBrowser for help on using the repository browser.