jesterxl

Flash Symbol Container

Oct 24th, 2011
253
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package
  2. {
  3.    
  4.     import flash.display.Bitmap;
  5.     import flash.display.BitmapData;
  6.     import flash.display.BlendMode;
  7.     import flash.display.DisplayObject;
  8.     import flash.geom.ColorTransform;
  9.     import flash.geom.Matrix;
  10.    
  11.     import mx.core.UIComponent;
  12.    
  13.     [DefaultProperty("children")]
  14.     public class FlashSymbolContainer extends UIComponent
  15.     {
  16.        
  17.         private var _children:Array;
  18.         private var childrenDirty:Boolean = false;
  19.        
  20.         public function get children():Array { return _children; }
  21.         public function set children(value:Array):void
  22.         {
  23.             if(value != null)
  24.             {
  25.                 _children = value;
  26.                 childrenDirty = true;
  27.                 invalidateProperties();
  28.             }
  29.         }
  30.         public function FlashSymbolContainer()
  31.         {
  32.             super();
  33.            
  34.             width   = 300;
  35.             height  = 200;
  36.         }
  37.        
  38.         protected override function commitProperties():void
  39.         {
  40.             super.commitProperties();
  41.            
  42.             if(childrenDirty)
  43.             {
  44.                 childrenDirty = false;
  45.                 redraw();
  46.             }
  47.         }
  48.        
  49.         private function redraw():void
  50.         {
  51.             if(_children == null)
  52.                 return;
  53.            
  54.             var len:int = _children.length;
  55.             if(len == 0)
  56.                 return;
  57.            
  58.             for(var index:int = 0; index < len; index++)
  59.             {
  60.                 var obj:DisplayObject = _children[index] as DisplayObject;
  61.                 if(obj == null)
  62.                 {
  63.                     throw new Error("Children must be of type DisplayObject.");
  64.                     return;
  65.                 }
  66.                
  67.                 if(obj.parent)
  68.                     obj.parent.removeChild(obj);
  69.                
  70.                 addChild(obj);
  71.             }
  72.         }
  73.     }
  74. }
  75.  
Advertisement
Add Comment
Please, Sign In to add comment