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

Revision 1, 1.6 kB (checked in by jeroen, 18 months ago)

initial commit of old repository into public one

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
23
24        /**
25        * Constructor.
26        *
27        * @param skn    The MovieClip that contains the display, playlist and controlbar.
28        **/
29        public function Skinner(skn:MovieClip) {
30                skin = skn;
31        };
32
33
34        /**
35        * Start the loading process.
36        *
37        * @param cfg    Object that contains all docking parameters.
38        **/
39        public function load(url:String=undefined) {
40                if(url) {
41                        loader = new Loader();
42                        loader.contentLoaderInfo.addEventListener(Event.COMPLETE,loaderHandler);
43                        loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR,errorHandler);
44                        try {
45                                loader.load(new URLRequest(url));
46                        } catch (err:Error) {
47                                dispatchEvent(new Event(Event.COMPLETE));
48                        }
49                } else {
50                        dispatchEvent(new Event(Event.COMPLETE));
51                }
52        };
53
54
55        /** SWF loading failed; use default skin. **/
56        private function errorHandler(evt:IOErrorEvent) {
57                dispatchEvent(new Event(Event.COMPLETE));
58        };
59
60
61        /** SWF loading completed; add to stage and populate. **/
62        private function loaderHandler(evt:Event) {
63                var cnt = MovieClip(loader.content);
64                while(cnt.numChildren > 0) {
65                        var ncd = cnt.getChildAt(0);
66                        var ocd = skin.getChildByName(ncd.name);
67                        skin.removeChild(ocd);
68                        skin.addChild(ncd);
69                }
70                dispatchEvent(new Event(Event.COMPLETE));
71        };
72
73
74}
75
76
77}
Note: See TracBrowser for help on using the browser.