/** * Wrap all views and plugins and provides them with MVC access pointers. **/ package com.jeroenwijering.player { import com.jeroenwijering.events.*; import com.jeroenwijering.utils.*; import flash.display.*; import flash.events.*; import flash.external.ExternalInterface; import flash.system.*; import flash.ui.ContextMenu; import flash.utils.setTimeout; public class View extends AbstractView { /** Object with all configuration parameters **/ private var _config:Object; /** Reference to all stage graphics. **/ private var _skin:MovieClip; /** Object that load the skin and plugins. **/ private var sploader:SPLoader; /** Controller of the MVC cycle. **/ private var controller:Controller; /** Model of the MVC cycle. **/ private var model:Model; /** Reference to the contextmenu. **/ private var context:ContextMenu; /** A list with all javascript listeners. **/ private var listeners:Array; /** Player is ready **/ private var ready:Boolean; /** Constructor, save references and subscribe to events. **/ public function View(cfg:Object,skn:MovieClip,ldr:SPLoader,ctr:Controller,mdl:Model):void { Security.allowDomain("*"); _config = cfg; _config['client'] = 'FLASH '+Capabilities.version; _skin = skn; _skin.stage.scaleMode = "noScale"; _skin.stage.align = "TL"; _skin.stage.addEventListener(Event.RESIZE,resizeHandler); sploader = ldr; controller = ctr; model = mdl; setListening(); listeners = new Array(); }; /** Getters for the config parameters, skinning parameters and playlist. **/ override public function get config():Object { return _config; }; override public function get playlist():Array { return controller.playlist; }; override public function get skin():MovieClip { return _skin; }; /** Subscribers to the controller, model and view. **/ override public function addControllerListener(typ:String,fcn:Function):void { controller.addEventListener(typ.toUpperCase(),fcn); }; private function addJSControllerListener(typ:String,fcn:String):Boolean { listeners.push({target:'CONTROLLER',type:typ.toUpperCase(),callee:fcn}); return true; }; override public function addModelListener(typ:String,fcn:Function):void { model.addEventListener(typ.toUpperCase(),fcn); }; private function addJSModelListener(typ:String,fcn:String):Boolean { listeners.push({target:'MODEL',type:typ.toUpperCase(),callee:fcn}); return true; }; override public function addViewListener(typ:String,fcn:Function):void { this.addEventListener(typ.toUpperCase(),fcn); }; private function addJSViewListener(typ:String,fcn:String):Boolean { listeners.push({target:'VIEW',type:typ.toUpperCase(),callee:fcn}); return true; }; /** Send event to listeners and tracers. **/ private function forward(tgt:String,typ:String,dat:Object):void { var prm:String = ''; for (var i:String in dat) { prm += i+':'+dat[i]+','; } if(prm.length > 0) { prm = '('+prm.substr(0,prm.length-1)+')'; } if(!dat) { dat = new Object(); } dat.id = config['id']; dat.client = config['client']; dat.version = config['version']; for (var itm:String in listeners) { if(listeners[itm]['target'] == tgt && listeners[itm]['type'] == typ) { ExternalInterface.call(listeners[itm]['callee'],dat); } } }; /** Javascript getters for the config, pluginconfig and playlist. **/ private function getConfig():Object { var cfg:Object = new Object(); for(var s:String in _config) { if(s.indexOf('.') == -1 && _config[s] != undefined) { cfg[s] = _config[s]; } } return cfg; }; /** Return the current playlist. **/ private function getPlaylist():Array { var arr:Array = new Array(); var cfg:Object = new Object(); if(controller.playlist) { for(var i:Number=0; i