source: plugins/infobox/com/jeroenwijering/plugins/InfoBox.as @ 394

Revision 394, 3.8 KB checked in by jeroen, 4 years ago (diff)

added a color flashvar to the infobox and fixed a few wowza compatibility issues

Line 
1package com.jeroenwijering.plugins {
2
3
4import com.jeroenwijering.events.*;
5
6import flash.display.*;
7import flash.events.*;
8import flash.geom.Rectangle;
9import flash.text.*;
10
11/**
12* A simple plugin that displays a search bar.
13**/
14public class InfoBox extends MovieClip implements PluginInterface {
15
16
17        /** Reference to the background clip. **/
18        private var back:Sprite;
19        /** Default colors. **/
20        private var colors:Array = new Array('FFFFFF','000000');
21        /** Reference to the graphics. **/
22        public var config:Object = {
23                color:undefined,
24                size:85,
25                position:'bottom'
26        };
27        /** Reference to the title textfield. **/
28        private var title:TextField;
29        /** Reference to the description textfield. **/
30        private var description:TextField;
31        /** Reference to the author textfield. **/
32        private var author:TextField;
33        /** Reference to the date textfield. **/
34        private var date:TextField;
35        /** Reference to the View of the player. **/
36        private var view:AbstractView;
37
38
39        /** Constructor. **/
40        public function InfoBox():void {};
41
42
43        /** Build the clip graphics. **/
44        private function build():void {
45                back = new Sprite();
46                back.graphics.beginFill(uint('0x'+colors[0]));
47                back.graphics.drawRect(0,0,400,40);
48                addChild(back);
49                title = new TextField();
50                title.defaultTextFormat = new TextFormat("_sans",13,uint('0x'+colors[1]),true);
51                title.x = title.y = 5;
52                addChild(title);
53                description = new TextField();
54                description.defaultTextFormat = new TextFormat("_sans",11,uint('0x'+colors[1]));
55                description.multiline = description.wordWrap = true;
56                description.x = 5;
57                description.y = 25;
58                addChild(description);
59                author = new TextField();
60                author.defaultTextFormat = new TextFormat("_sans",10,uint('0x'+colors[1]));
61                author.x = 5;
62                addChild(author);
63                date = new TextField();
64                date.defaultTextFormat = new TextFormat("_sans",10,uint('0x'+colors[1]));
65                addChild(date);
66        };
67
68
69
70        /** The initialize call is invoked by the player View. **/
71        public function initializePlugin(vie:AbstractView):void {
72                view = vie;
73                view.addControllerListener(ControllerEvent.RESIZE,resizeHandler);
74                if(view.config['backcolor']) { colors[0] = view.config['backcolor']; }
75                if(view.config['frontcolor']) { colors[1] = colors[2] = view.config['frontcolor']; }
76                if(config['color']) { colors[1] = config['color']; }
77                view.addControllerListener(ControllerEvent.PLAYLIST,itemHandler);
78                view.addControllerListener(ControllerEvent.ITEM,itemHandler);
79                build();
80                resizeHandler();
81                if(config['position'] == 'over') {
82                        back.alpha = 0.8;
83                        mouseEnabled = false;
84                        mouseChildren = false;
85                        view.addModelListener(ModelEvent.STATE,stateHandler);
86                }
87        };
88
89
90        /** Repopulate the texts on item change. **/
91        private function itemHandler(evt:ControllerEvent):void {
92                var itm:Object = view.playlist[view.config['item']];
93                title.text = itm['title'] + ' ';
94                description.text = itm['description'] + ' ';
95                author.htmlText = '<b>Source:</b> ' + itm['author'] + ' ';
96                date.htmlText = '<b>Added:</b> ' + itm['date'] + ' ';
97        };
98
99
100        /** Handle a resize. **/
101        private function resizeHandler(evt:ControllerEvent=undefined):void {
102                back.width = view.config['width'];
103                if(config['width']) {
104                        visible = config['visible'];
105                        x = config['x'];
106                        y = config['y'] + config['height'] - config['size'];
107                        back.width = config['width'];
108                        back.height = config['size'];
109                }
110                title.width = description.width = back.width - 10;
111                description.height = back.height - 45;
112                author.y = date.y = back.height - 25;
113                author.width = date.width = back.width/2 - 5;
114                date.x = back.width/2;
115        };
116
117
118        /** When the box position is "over", the box is hidden when the video plays. **/
119        private function stateHandler(evt:ModelEvent):void {
120                switch (evt.data.newstate) {
121                        case ModelStates.BUFFERING:
122                        case ModelStates.PLAYING:
123                                visible = false;
124                                break;
125                        default:
126                                visible = true;
127                                break;
128                }
129        };
130
131
132}
133
134
135}
Note: See TracBrowser for help on using the repository browser.