ActionScript组件开发

http://sunshineyao.iteye.com/blog/827432

 

 

 近日工作中需要用到类似Windows那种罕有最大化、最小化、关闭功能的TitleWindow,而Flex本身并无这个组件(Flex AI有NativeWindow这个组件)。于是上网搜索,发现了MDI,但是感觉代码太多而且代码侵入性很强不便于扩展,其更适合与在一个空间内存在多个Panel的场景,ResizeTitleWindow与ResizeManage更使用于我的应用场景,我最终使用的是ResizeManag这个组件但不幸的是下载下来的资源也是有残缺,心想反正自己也是得做扩展的因而放弃了寻找完全可用版的努力,继而开始研究源代码并进行了相应的修改与扩展。 

ResizeWindow.as 

Java代码   收藏代码
  1. package sjd.containers  
  2. {  
  3.     import flash.events.MouseEvent;  
  4.     import flash.geom.Point;  
  5.       
  6.     import mx.containers.Form;  
  7.     import mx.containers.FormItem;  
  8.     import mx.containers.TitleWindow;  
  9.     import mx.controls.Button;  
  10.     import mx.controls.TextInput;  
  11.     import mx.core.Application;  
  12.     import mx.events.FlexEvent;  
  13.       
  14.     import sjd.utils.CursorUtil;  
  15.    
  16.   [Event(name="closeWindow", type="mx.events.FlexEvent")]  
  17.   [Event(name="minWindow", type="mx.events.FlexEvent")]  
  18.   [Event(name="maxWindow", type="mx.events.FlexEvent")]  
  19.        
  20.   /** 
  21.    * @class ResizeWindow 
  22.    * @brief A TitleWindow with Resize Enabled and Max, Min, Close Button 
  23.    * @author Jove 
  24.    * @version 1.1 
  25.    */  
  26.   public class ResizeWindow extends TitleWindow{  
  27.      
  28.     private static const SIDE_OTHER:Number = 0;  
  29.     private static const SIDE_TOP:Number = 1;  
  30.     private static const SIDE_BOTTOM:Number = 2;  
  31.     private static const SIDE_LEFT:Number = 4;  
  32.     private static const SIDE_RIGHT:Number = 8;  
  33.      
  34.     private static var resizeObj:Object;  
  35.     private static var mouseState:Number = 0;  
  36.     private static var mouseMargin:Number = 10;  
  37.      
  38.     [Embed(source="/sjd/assets/verticalSize.gif")]  
  39.     private var verticalSize:Class;  
  40.     [Embed(source="/sjd/assets/horizontalSize.gif")]  
  41.     private var horizontalSize:Class;  
  42.     [Embed(source="/sjd/assets/leftObliqueSize.gif")]  
  43.     private var leftObliqueSize:Class;  
  44.     [Embed(source="/sjd/assets/rightObliqueSize.gif")]  
  45.     private var rightObliqueSize:Class;  
  46.      
  47.     private var oWidth:Number = 0;  
  48.     private var oHeight:Number = 0;  
  49.     private var oX:Number = 0;  
  50.     private var oY:Number = 0;  
  51.     private var oPoint:Point = new Point();  
  52.      
  53.     private var _showWindowButtons:Boolean = true;  
  54.     private var _windowMinSize:Number = 150;  
  55.      
  56.     //private var form:MyForm = new MyForm();  
  57.     /** 
  58.       * Constructor. 
  59.       * Add mouse envent to this window and application. 
  60.       * initialize the old positions. 
  61.       */  
  62.     public function ResizeWindow(){  
  63.       super();  
  64.       addContent();  
  65.       initPosition(this);  
  66.         
  67.       this.addEventListener(MouseEvent.MOUSE_MOVE, oMouseMove);  
  68.       this.addEventListener(MouseEvent.MOUSE_OUT, oMouseOut);  
  69.       this.addEventListener(MouseEvent.MOUSE_DOWN, oMouseDown);  
  70.       //this.addEventListener(MouseEvent.MOUSE_UP, oMouseUp);  
  71.       this.addEventListener(FlexEvent.CREATION_COMPLETE, addButton);  
  72.        
  73.       //Application.application.parent:SystemManager  
  74.       Application.application.parent.addEventListener(MouseEvent.MOUSE_UP, oMouseUp);  
  75.       Application.application.parent.addEventListener(MouseEvent.MOUSE_MOVE, oResize);  
  76.     }  
  77.       
  78.     private function addContent():void{  
  79.         var form:Form  = new Form();  
  80.         var formItem1:FormItem = new FormItem();  
  81.         formItem1.label = "事件源";  
  82.         var text:TextInput = new TextInput();  
  83.         formItem1.addChild(text);  
  84.         form.width = 200;  
  85.         form.addChild(formItem1);  
  86.         //form.width = this.width;  
  87.         //form.height = this.height;  
  88.         this.addChild(form);  
  89.         //this.updateDisplayList(100,100);  
  90.     }  
  91.      
  92.     public function set showWindowButtons(show:Boolean):void{  
  93.       _showWindowButtons = show;  
  94.       if(titleBar != null){  
  95.         addButton(new FlexEvent(""));  
  96.       }  
  97.     }  
  98.      
  99.     public function get showWindowButtons():Boolean{  
  100.       return _showWindowButtons;  
  101.     }  
  102.      
  103.     public function set windowMinSize(size:Number):void{  
  104.       if(size > 0){  
  105.         _windowMinSize = size;  
  106.       }  
  107.     }  
  108.      
  109.     public function get windowMinSize():Number{  
  110.       return _windowMinSize;  
  111.     }  
  112.      
  113.     private static function initPosition(obj:Object):void{  
  114.       obj.oHeight = obj.height;  
  115.       obj.oWidth = obj.width;  
  116.       obj.oX = obj.x;  
  117.       obj.oY = obj.y;  
  118.     }  
  119.      
  120.     /** 
  121.      * Set the first global point that mouse down on the window. 
  122.      * @param The MouseEvent.MOUSE_DOWN 
  123.      */  
  124.     private function oMouseDown(event:MouseEvent):void{  
  125.       if(mouseState != SIDE_OTHER){  
  126.         resizeObj = event.currentTarget;  
  127.         initPosition(resizeObj);  
  128.         oPoint.x = resizeObj.mouseX;  
  129.         oPoint.y = resizeObj.mouseY;  
  130.         oPoint = this.localToGlobal(oPoint);  
  131.       }  
  132. font-size: 1em; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 38px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; border-left-width: 1px; border-left-style: solid; border-left-color: #d1d7dc; background-color:
分享到:
评论

你可能感兴趣的:(Flex,Flash,ITeye,UP,actionscript)