| 1 | package 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 | var cls:Class; |
|---|
| 20 | try { |
|---|
| 21 | cls = tgt.loaderInfo.applicationDomain.getDefinition(nam) as Class; |
|---|
| 22 | } catch (e:Error) { |
|---|
| 23 | cls = Object(tgt).constructor; |
|---|
| 24 | } |
|---|
| 25 | var dup:* = new cls(); |
|---|
| 26 | dup.transform = tgt.transform; |
|---|
| 27 | dup.filters = tgt.filters; |
|---|
| 28 | dup.cacheAsBitmap = tgt.cacheAsBitmap; |
|---|
| 29 | dup.opaqueBackground = tgt.opaqueBackground; |
|---|
| 30 | dup.name = tgt.name; |
|---|
| 31 | if (adc == true) { |
|---|
| 32 | var idx:Number = tgt.parent.getChildIndex(tgt); |
|---|
| 33 | tgt.parent.addChildAt(dup, idx + 1); |
|---|
| 34 | } |
|---|
| 35 | return dup; |
|---|
| 36 | } |
|---|
| 37 | |
|---|
| 38 | |
|---|
| 39 | /** |
|---|
| 40 | * Completely clear the contents of a displayobject. |
|---|
| 41 | * |
|---|
| 42 | * @param tgt Displayobject to clear. |
|---|
| 43 | **/ |
|---|
| 44 | public static function clear(tgt:DisplayObjectContainer):void { |
|---|
| 45 | var len:Number = tgt.numChildren; |
|---|
| 46 | for (var i:Number = 0; i < len; i++) { |
|---|
| 47 | tgt.removeChildAt(0); |
|---|
| 48 | } |
|---|
| 49 | tgt.scaleX = tgt.scaleY = 1; |
|---|
| 50 | } |
|---|
| 51 | |
|---|
| 52 | |
|---|
| 53 | /** |
|---|
| 54 | * Draw a rectangle on stage. |
|---|
| 55 | * |
|---|
| 56 | * @param tgt Displayobject to add the rectangle to. |
|---|
| 57 | * @param col Color of the rectangle. |
|---|
| 58 | * @param wid Width of the rectangle. |
|---|
| 59 | * @param hei Height of the rectangle. |
|---|
| 60 | * @param xps X offset of the rectangle, defaults to 0. |
|---|
| 61 | * @param yps Y offset of the rectangle, defaults to 0. |
|---|
| 62 | * @param alp Alpha value of the rectangle, defaults to 0. |
|---|
| 63 | * @return A reference to the newly drawn rectangle. |
|---|
| 64 | **/ |
|---|
| 65 | public static function rect(tgt:Sprite, col:String, wid:Number, hei:Number, xps:Number = 0, yps:Number = 0, alp:Number = 1):Sprite { |
|---|
| 66 | var rct:Sprite = new Sprite(); |
|---|
| 67 | rct.x = xps; |
|---|
| 68 | rct.y = yps; |
|---|
| 69 | rct.graphics.beginFill(uint('0x' + col), alp); |
|---|
| 70 | rct.graphics.drawRect(0, 0, wid, hei); |
|---|
| 71 | tgt.addChild(rct); |
|---|
| 72 | return rct; |
|---|
| 73 | }; |
|---|
| 74 | } |
|---|
| 75 | } |
|---|