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

Revision 66, 3.2 KB checked in by jeroen, 5 years ago (diff)

string of bugfixes and enahncements to the 4.2 player - see changelog

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