root/trunk/as3/com/jeroenwijering/utils/Skinner.as @ 2

Revision 2, 1.7 kB (checked in by jeroen, 18 months ago)

fixes in skinning and controlbar

Line 
1/**
2* Loads external SWF skin and calculates dimensions.
3**/
4
5
6package com.jeroenwijering.utils {
7
8
9import flash.display.Loader;
10import flash.display.MovieClip;
11import flash.events.*;
12import flash.net.URLRequest;
13
14
15public class Skinner extends EventDispatcher {
16
17
18        /** Reference to the stage graphics **/
19        public var skin:MovieClip;
20        /** SWF skin loader reference **/
21        private var loader:Loader;
22        /** Skinnable elements **/
23        private var ELEMENTS:Array = new Array("controlbar","display","playlist");
24
25
26        /**
27        * Constructor.
28        *
29        * @param skn    The MovieClip that contains the display, playlist and controlbar.
30        **/
31        public function Skinner(skn:MovieClip) {
32                skin = skn;
33        };
34
35
36        /**
37        * Start the loading process.
38        *
39        * @param cfg    Object that contains all docking parameters.
40        **/
41        public function load(url:String=undefined) {
42                if(url) {
43                        loader = new Loader();
44                        loader.contentLoaderInfo.addEventListener(Event.COMPLETE,loaderHandler);
45                        loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR,errorHandler);
46                        try {
47                                loader.load(new URLRequest(url));
48                        } catch (err:Error) {
49                                dispatchEvent(new Event(Event.COMPLETE));
50                        }
51                } else {
52                        dispatchEvent(new Event(Event.COMPLETE));
53                }
54        };
55
56
57        /** SWF loading failed; use default skin. **/
58        private function errorHandler(evt:IOErrorEvent) {
59                dispatchEvent(new Event(Event.COMPLETE));
60        };
61
62
63        /** SWF loading completed; add to stage and populate. **/
64        private function loaderHandler(evt:Event) {
65                var cnt = MovieClip(loader.content);
66                for(var i=0; i<cnt.numChildren; i++) {
67                        var ncd = cnt.getChildAt(i);
68                        var ocd = skin.getChildByName(ncd.name);
69                        if(ocd) {
70                                skin.removeChild(ocd);
71                                skin.addChild(ncd);
72                                skin[ncd.name] = ncd;
73                        }
74                }
75                dispatchEvent(new Event(Event.COMPLETE));
76        };
77
78
79}
80
81
82}
Note: See TracBrowser for help on using the browser.