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

Revision 1, 2.7 kB (checked in by jeroen, 18 months ago)

initial commit of old repository into public one

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