Mega Code Archive

 
Categories / Flex / Container
 

A Tile Container with draggable children

<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">     <mx:Tile width="300" height="600" direction="horizontal">         <mx:Script>                              import mx.core.UIComponent;                      private function childStartDrag(event:Event):void                 {                     (event.currentTarget as UIComponent).startDrag(false, this.getBounds(stage));                     (event.currentTarget as UIComponent).addEventListener(MouseEvent.MOUSE_DOWN, childStopDrag);                     swapChildren((event.currentTarget as UIComponent), getChildAt(numChildren-1));                 }                      private function childStopDrag(event:Event):void                 {                     swapChildren((event.currentTarget as UIComponent),hitTestChild((event.currentTarget as UIComponent)));                     (event.currentTarget as UIComponent).stopDrag();                     this.invalidateDisplayList();                 }                      private function hitTestChild(obj:UIComponent):DisplayObject                 {                     for(var i:int = 0; i<this.numChildren; i++)                     {                         if(this.getChildAt(i).hitTestObject(obj))                         {                             return getChildAt(i);                         }                     }                     return getChildAt(0)                 }                              </mx:Script>         <mx:Panel title="First Panel" mouseDown="childStartDrag(event)">             <mx:Text text="First Text"/>         </mx:Panel>     </mx:Tile> </mx:Application>