| 1 | /** |
|---|
| 2 | * Wrap all views and plugins and provides them with MVC access pointers. |
|---|
| 3 | **/ |
|---|
| 4 | package com.jeroenwijering.player { |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | import flash.display.MovieClip; |
|---|
| 8 | import flash.events.EventDispatcher; |
|---|
| 9 | import flash.external.ExternalInterface; |
|---|
| 10 | import flash.system.Capabilities; |
|---|
| 11 | import com.jeroenwijering.events.*; |
|---|
| 12 | import com.jeroenwijering.player.*; |
|---|
| 13 | import com.jeroenwijering.views.*; |
|---|
| 14 | |
|---|
| 15 | |
|---|
| 16 | public 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 | } |
|---|