source: trunk/as3/com/jeroenwijering/player/View.as @ 7

Revision 7, 2.8 KB checked in by jeroen, 5 years ago (diff)

added some skinning fixes and the first two skins|

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