root/trunk/as3/com/jeroenwijering/player/View.as @ 2

Revision 2, 2.8 kB (checked in by jeroen, 18 months ago)

fixes in skinning and controlbar

  • Property svn:executable set to *
Line 
1/**
2* Wrap all views and plugins and provides them with MVC access pointers.
3**/
4package com.jeroenwijering.player {
5
6
7import flash.display.MovieClip;
8import flash.events.EventDispatcher;
9import flash.external.ExternalInterface;
10import flash.system.Capabilities;
11import com.jeroenwijering.events.*;
12import com.jeroenwijering.player.*;
13import com.jeroenwijering.views.*;
14
15
16public class View extends EventDispatcher {
17
18
19        /** Object with all configuration parameters **/
20        private var _config:Object;
21        /** Clip with all graphical elements **/
22        private var _skin:MovieClip;
23        /** Controller of the MVC cycle. **/
24        private var controller:Controller;
25        /** Model of the MVC cycle. **/
26        private var model:Model;
27        /** A list with all the currently active views. **/
28        private var views:Array;
29
30
31        /** Constructor, save references and subscribe to events. **/
32        public function View(cfg:Object,skn:MovieClip,ctr:Controller,mdl:Model) {
33                _config = cfg;
34                _skin = skn;
35                _config['controlbarsize'] = _skin['controlbar'].height;
36                controller = ctr;
37                model = mdl;
38                addViews();
39        };
40
41
42        /** Add all child views. **/
43        private function addViews() {
44                views = new Array();
45                views.push(new CaptionsView(this));
46                views.push(new DisplayView(this));
47                views.push(new KeyboardView(this));
48                views.push(new RightclickView(this));
49                if(_skin['controlbar']) {
50                        views.push(new ControlbarView(this));
51                }
52                if(_skin['playlist']) {
53                        views.push(new PlaylistView(this));
54                }
55                if(ExternalInterface.available || Capabilities.playerType == 'External') {
56                        views.push(new ExternalView(this));
57                }
58        };
59
60
61        /**  Getters for the config parameters, skinning parameters and playlist. **/
62        public function get config():Object { return _config; };
63        public function get playlist():Array { return controller.playlist; };
64        public function get skin():MovieClip { return _skin; };
65
66
67        /**  Subscribers to the controller and model. **/
68        public function addControllerListener(typ:String,fcn:Function) {
69                controller.addEventListener(typ.toUpperCase(),fcn);
70        };
71        public function addModelListener(typ:String,fcn:Function) {
72                model.addEventListener(typ.toUpperCase(),fcn);
73        };
74        public function addViewListener(typ:String,fcn:Function) {
75                this.addEventListener(typ.toUpperCase(),fcn);
76        };
77
78
79        /**  Dispatch events. **/
80        public function sendEvent(typ:String,prm:Object=undefined) {
81                typ = typ.toUpperCase();
82                var dat = new Object();
83                switch(typ) {
84                        case 'ERROR':
85                                dat['message'] = prm;
86                                break;
87                        case 'LINK':
88                                dat['index'] = prm;
89                                break;
90                        case 'LOAD':
91                                dat['object'] = prm;
92                                break;
93                        case 'ITEM':
94                                dat['index'] = prm;
95                                break;
96                        case 'SEEK':
97                                dat['position'] = prm;
98                                break;
99                        case 'VOLUME':
100                                dat['percentage'] = prm;
101                                break;
102                        default:
103                                if(prm) { dat['state'] = prm; }
104                                break;
105                }
106                dispatchEvent(new ViewEvent(typ,dat));
107        };
108
109
110}
111
112
113}
Note: See TracBrowser for help on using the browser.