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

Revision 4, 2.6 kB (checked in by jeroen, 18 months ago)

implemented stacker; display of media and some controlbaritems still broken

  • 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['controlbarsize'] = _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 ControlbarView(this));
46                views.push(new DisplayView(this));
47                views.push(new ExternalView(this));
48                views.push(new KeyboardView(this));
49                views.push(new RightclickView(this));
50                views.push(new PlaylistView(this));
51        };
52
53
54        /**  Getters for the config parameters, skinning parameters and playlist. **/
55        public function get config():Object { return _config; };
56        public function get playlist():Array { return controller.playlist; };
57        public function get skin():MovieClip { return _skin; };
58
59
60        /**  Subscribers to the controller and model. **/
61        public function addControllerListener(typ:String,fcn:Function) {
62                controller.addEventListener(typ.toUpperCase(),fcn);
63        };
64        public function addModelListener(typ:String,fcn:Function) {
65                model.addEventListener(typ.toUpperCase(),fcn);
66        };
67        public function addViewListener(typ:String,fcn:Function) {
68                this.addEventListener(typ.toUpperCase(),fcn);
69        };
70
71
72        /**  Dispatch events. **/
73        public function sendEvent(typ:String,prm:Object=undefined) {
74                typ = typ.toUpperCase();
75                var dat = new Object();
76                switch(typ) {
77                        case 'ERROR':
78                                dat['message'] = prm;
79                                break;
80                        case 'LINK':
81                                dat['index'] = prm;
82                                break;
83                        case 'LOAD':
84                                dat['object'] = prm;
85                                break;
86                        case 'ITEM':
87                                dat['index'] = prm;
88                                break;
89                        case 'SEEK':
90                                dat['position'] = prm;
91                                break;
92                        case 'VOLUME':
93                                dat['percentage'] = prm;
94                                break;
95                        default:
96                                if(prm) { dat['state'] = prm; }
97                                break;
98                }
99                dispatchEvent(new ViewEvent(typ,dat));
100        };
101
102
103}
104
105
106}
Note: See TracBrowser for help on using the browser.