source: trunk/fl5/src/com/longtailvideo/jwplayer/utils/Draw.as @ 588

Revision 588, 2.3 KB checked in by pablo, 4 years ago (diff)

V5 Skin update

Line 
1package com.longtailvideo.jwplayer.utils {
2        import flash.display.DisplayObject;
3        import flash.display.Sprite;
4        import flash.utils.getQualifiedClassName;
5        import flash.display.DisplayObjectContainer;
6       
7       
8        public class Draw {
9                /**
10                 * Clone a sprite / movieclip.
11                 *
12                 * @param tgt   Sprite to clone.
13                 * @param adc   Add as child to the parent displayobject.
14                 *
15                 * @return              The clone; not yet added to the displaystack.
16                 **/
17                public static function clone(tgt:Sprite, adc:Boolean = false):DisplayObject {
18                        var nam:String = getQualifiedClassName(tgt);
19                        if (nam == "flash.display::MovieClip") return tgt;
20                       
21                        var cls:Class;
22                        try {
23                                cls = tgt.loaderInfo.applicationDomain.getDefinition(nam) as Class;
24                        } catch (e:Error) {
25                                cls = Object(tgt).constructor;
26                        }
27                        var dup:* = new cls();
28                        dup.transform = tgt.transform;
29                        dup.filters = tgt.filters;
30                        dup.cacheAsBitmap = tgt.cacheAsBitmap;
31                        dup.opaqueBackground = tgt.opaqueBackground;
32                        dup.name = tgt.name;
33                        if (adc == true) {
34                                var idx:Number = tgt.parent.getChildIndex(tgt);
35                                tgt.parent.addChildAt(dup, idx + 1);
36                        }
37                        return dup;
38                }
39               
40               
41                /**
42                 * Completely clear the contents of a displayobject.
43                 *
44                 * @param tgt   Displayobject to clear.
45                 **/
46                public static function clear(tgt:DisplayObjectContainer):void {
47                        var len:Number = tgt.numChildren;
48                        for (var i:Number = 0; i < len; i++) {
49                                tgt.removeChildAt(0);
50                        }
51                        tgt.scaleX = tgt.scaleY = 1;
52                }
53               
54               
55                /**
56                 * Draw a rectangle on stage.
57                 *
58                 * @param tgt   Displayobject to add the rectangle to.
59                 * @param col   Color of the rectangle.
60                 * @param wid   Width of the rectangle.
61                 * @param hei   Height of the rectangle.
62                 * @param xps   X offset of the rectangle, defaults to 0.
63                 * @param yps   Y offset of the rectangle, defaults to 0.
64                 * @param alp   Alpha value of the rectangle, defaults to 0.
65                 * @return              A reference to the newly drawn rectangle.
66                 **/
67                public static function rect(tgt:Sprite, col:String, wid:Number, hei:Number, xps:Number = 0, yps:Number = 0, alp:Number = 1):Sprite {
68                        var rct:Sprite = new Sprite();
69                        rct.x = xps;
70                        rct.y = yps;
71                        rct.graphics.beginFill(uint('0x' + col), alp);
72                        rct.graphics.drawRect(0, 0, wid, hei);
73                        tgt.addChild(rct);
74                        return rct;
75                };
76        }
77}
Note: See TracBrowser for help on using the repository browser.