source: branches/4.2/com/jeroenwijering/player/SWFLoader.as @ 68

Revision 68, 3.1 KB checked in by jeroen, 5 years ago (diff)

added new feeditems, polished simple/thin skins and made sure large YT images are loaded by default

Line 
1/**
2* Loads external SWF skins and plugins.
3**/
4
5
6package com.jeroenwijering.player {
7
8
9import com.jeroenwijering.utils.Draw;
10import flash.display.Loader;
11import flash.display.MovieClip;
12import flash.events.*;
13import flash.net.URLRequest;
14import flash.system.*;
15
16
17public class SWFLoader extends EventDispatcher {
18
19
20        /** Reference to the player itself. **/
21        private var player:MovieClip;
22        /** SWF loader reference **/
23        private var loader:Loader;
24        /** Base directory for the plugins. **/
25        private var basedir:String = 'http://plugins.longtailvideo.com/';
26
27
28        /**
29        * Constructor.
30        *
31        * @param ply    The player instance.
32        **/
33        public function SWFLoader(ply:MovieClip):void {
34                player = ply;
35        };
36
37
38        /**
39        * Load a list of SWF plugins.
40        *
41        * @prm pgi      A commaseparated list with plugins.
42        **/
43        public function loadPlugins(pgi:String=null):void {
44                if(pgi) {
45                        var arr = pgi.split(',');
46                        for(var i in arr) { loadSWF(arr[i],false); }
47                }
48        };
49
50
51        /**
52        * Start the loading process.
53        *
54        * @param cfg    Object that contains all configuration parameters.
55        **/
56        public function loadSkin(skn:String=null):void {
57                if(skn) {
58                        loadSWF(skn,true);
59                } else {
60                        dispatchEvent(new Event(Event.COMPLETE));
61                }
62        };
63
64
65        /** Load a particular SWF file. **/
66        public function loadSWF(str:String,skn:Boolean):void {
67                if(str.substr(-4) != '.swf') { str += '.swf'; }
68                var ldr = new Loader();
69                if(skn) {
70                        ldr.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR,skinError);
71                        ldr.contentLoaderInfo.addEventListener(Event.INIT,skinHandler);
72                } else {
73                        player.skin.addChild(ldr);
74                        player.skin.swapChildren(player.skin.controlbar,ldr);
75                        ldr.visible = false;
76                        ldr.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR,pluginError);
77                        ldr.contentLoaderInfo.addEventListener(Event.INIT,pluginHandler);
78                }
79                if(player.loaderInfo.url.indexOf('http') == 0) {
80                        var ctx = new LoaderContext(true,ApplicationDomain.currentDomain,SecurityDomain.currentDomain);
81                        if(skn) {
82                                ldr.load(new URLRequest(str),ctx);
83                        } else if (str.indexOf('http') == 0) {
84                                ldr.load(new URLRequest(str),ctx);
85                        } else {
86                                ldr.load(new URLRequest(basedir+str),ctx);
87                        }
88                } else {
89                        ldr.load(new URLRequest(str));
90                }
91        };
92
93
94        /** SWF loading failed. **/
95        private function pluginError(evt:IOErrorEvent):void {
96                player.view.sendEvent('TRACE',' plugin: '+evt.text);
97        };
98
99
100        /** Plugin loading completed; add to stage and populate. **/
101        private function pluginHandler(evt:Event):void {
102                try {
103                        evt.target.content.initializePlugin(player.view);
104                        evt.target.loader.visible = true;
105                } catch(err:Error) {
106                        player.view.sendEvent('TRACE',' plugin: '+err.message);
107                }
108        };
109
110
111        /** SWF loading failed; use default skin. **/
112        private function skinError(evt:IOErrorEvent=null):void {
113                player.skin = player['player'];
114                dispatchEvent(new Event(Event.COMPLETE));
115        };
116
117
118        /** Skin loading completed; add to stage and populate. **/
119        private function skinHandler(evt:Event):void {
120                var clp = evt.target.content;
121                if(clp['player']) {
122                        player.skin = MovieClip(clp['player']);
123                        Draw.clear(player);
124                        player.addChild(player.skin);
125                        dispatchEvent(new Event(Event.COMPLETE));
126                } else {
127                        skinError();
128                }
129        };
130
131}
132
133
134}
Note: See TracBrowser for help on using the repository browser.