+ -
当前位置:首页 → 问答吧 → 求高手帮助,怎么用鼠标拖动左右上下可以改变控件大小

求高手帮助,怎么用鼠标拖动左右上下可以改变控件大小

时间:2011-05-27

来源:互联网

143617lwhdl7pyjtd9p37l.png (1 KB)
控件
2011-5-27 10:18
求高手帮助,怎么用鼠标拖动左右上下可以改变控件大小

这个是控件代码
/****************控件代码********************************/
<?xml version="1.0" encoding="utf-8"?>
<s:BorderContainer xmlns:fx="http://ns.adobe.com/mxml/2009" borderWeight="14" borderAlpha="0.7" borderColor="0x698B22" minHeight="80" mouseOver="bordercontainer1_mouseOverHandler(event)" buttonMode="true"
                   xmlns:s="library://ns.adobe.com/flex/spark" cornerRadius="10" mouseDown="bordercontainer1_mouseDownHandler(event)"  useHandCursor="true" mouseOut="bordercontainer1_mouseOutHandler(event)"
                   xmlns:mx="library://ns.adobe.com/flex/mx" mouseUp="bordercontainer1_mouseUpHandler(event)"  contentBackgroundAlpha="0" backgroundAlpha="0">
    <s:layout>
        <s:BasicLayout/>
    </s:layout>

    <fx:Script>
        <![CDATA[
            [Bindable]
            public var iWidth:uint = 200;
            [Bindable]
            public var iMinHeight:uint = 80;
            
            protected function bordercontainer1_mouseDownHandler(event:MouseEvent):void
            {
                this.startDrag(false);
                event.stopPropagation();
            }

            protected function bordercontainer1_mouseUpHandler(event:MouseEvent):void
            {
                this.stopDrag();
            }

            protected function bordercontainer1_mouseOutHandler(event:MouseEvent):void
            {
                this.setStyle("borderVisible",false);
            }


            protected function bordercontainer1_mouseOverHandler(event:MouseEvent):void
            {
                this.setStyle("borderVisible",true);
            }


            protected function richeditabletext1_mouseDownHandler(event:MouseEvent):void
            {
                event.stopPropagation();
            }

        ]]>
    </fx:Script>

    <fx:Declarations>
        <!-- 将非可视元素(例如服务、值对象)放在此处 -->
    </fx:Declarations>
    <s:RichEditableText width="{iWidth}" fontSize="24" minHeight="{iMinHeight}" mouseDown="richeditabletext1_mouseDownHandler(event)"/>
</s:BorderContainer>

/************AS代码************************************/
package org.lanxy.draw
{
    import flash.events.EventDispatcher;
    import flash.events.MouseEvent;
    import flash.geom.Point;
   
    import mxml.EditTextField;
    import mxml.StampImage;
   
    import org.lanxy.graphic.Polyline;
    import org.lanxy.layers.GraphicsLayer;
   

    public class DrawTool extends EventDispatcher
    {
        private var graphicsLayer:GraphicsLayer;
        public static const FREELINE:String = "freeline";
        public static const LINE:String = "line";
        public static const EDITTEXTFIELD:String = "edit";
        public static const STAMPIMAGE:String = "sealimage";
        
        public var isActive:Boolean;
        private var isDrawing:Boolean;
        private var _drawType:String;
        private var polyline:Polyline;
        private var _firstPoint:Point;
        private var tmpLayer:GraphicsLayer;
        
        public function DrawTool(_graphicsLayer:GraphicsLayer)
        {
            graphicsLayer = _graphicsLayer;
            this.tmpLayer = _graphicsLayer;
        }
        
        public function get mgraphicsLayer():GraphicsLayer
        {
            return graphicsLayer;
        }
        
        public function activate(drawType:String):void
        {
            this.deactivate();
            if(this.graphicsLayer==null)
            {
                return;
            }
            this.isActive = true;
            this.graphicsLayer.addEventListener(MouseEvent.MOUSE_DOWN,this.onMouseDown);            
            switch (drawType)
            {
                case FREELINE:
                {
                    
                    break;
                }
                case LINE:
                {
                    
                    break;
                }
                case EDITTEXTFIELD:
                {
                    
                    break;
                }
                case STAMPIMAGE:
                {
                    
                    break;
                }
                default:
                    break;
            }
            this._drawType = drawType;
        }
        
        public function deactivate():void
        {
            if(!this.isActive)
            {
                return;
            }
            removeAllEventListeners();
            this._drawType = "";
            this.isActive =false;
        }
        
        private function removeAllEventListeners():void
        {
            if(this.graphicsLayer.hasEventListener(MouseEvent.MOUSE_DOWN)) this.tmpLayer.removeEventListener(MouseEvent.MOUSE_DOWN,this.onMouseDown);
            if(this.graphicsLayer.hasEventListener(MouseEvent.MOUSE_MOVE)) this.tmpLayer.removeEventListener(MouseEvent.MOUSE_MOVE,this.onMouseMove);
            if(this.graphicsLayer.hasEventListener(MouseEvent.MOUSE_UP)) this.tmpLayer.removeEventListener(MouseEvent.MOUSE_UP,this.onMouseUp);
            if(this.graphicsLayer.hasEventListener(MouseEvent.DOUBLE_CLICK)) this.tmpLayer.removeEventListener(MouseEvent.DOUBLE_CLICK,this.onDoubleClick);
        }
        
        private function onMouseDown(evt:MouseEvent):void
        {
            this.isDrawing = true;
            this.graphicsLayer.removeEventListener(MouseEvent.MOUSE_DOWN,this.onMouseDown);            
            switch(this._drawType)
            {
                case FREELINE:
                {
                    this.graphicsLayer.addEventListener(MouseEvent.MOUSE_MOVE,this.onMouseMove);
                    this.graphicsLayer.addEventListener(MouseEvent.MOUSE_UP,this.onMouseUp);
                    this.polyline = new Polyline();
                    this._firstPoint = new Point(evt.localX,evt.localY);
                    this.polyline.points.push(this._firstPoint);
                    this.graphicsLayer.addElement(this.polyline);
                    break;
                }
                case  EDITTEXTFIELD:
                {
                    var editField:EditTextField = new EditTextField();
                    editField.x = evt.localX;
                    editField.y = evt.localY;
                    this.graphicsLayer.addElement(editField);
                    break;
                }
                case  STAMPIMAGE:
                {
                    var stampImage:StampImage = new StampImage();
                    stampImage.x = evt.localX;
                    stampImage.y = evt.localY;
                    this.graphicsLayer.addElement(stampImage);
                    break;
                }
            }
            
        }
        
        private function onMouseMove(evt:MouseEvent):void
        {
            this.isDrawing = true;
            var tmpPnt:Point = new Point(evt.localX,evt.localY);
            switch(this._drawType)
            {
                case FREELINE:
                {
                    if(Point.distance(this._firstPoint,tmpPnt)>1 && Point.distance(this._firstPoint,tmpPnt)<30)
                    {
                        this._firstPoint = tmpPnt;
                        this.polyline.addPoint(tmpPnt);
                    }
                    this.polyline.refresh();
                }
            }
        }

        private function onMouseUp(evt:MouseEvent):void
        {
            this.isDrawing = false;
            this.graphicsLayer.removeEventListener(MouseEvent.MOUSE_MOVE,this.onMouseMove);
            this.graphicsLayer.removeEventListener(MouseEvent.MOUSE_UP,this.onMouseUp);
            this.graphicsLayer.addEventListener(MouseEvent.MOUSE_DOWN,this.onMouseDown);
            switch (this._drawType)
            {
                case FREELINE:
                {
                    break;
                }
            }
        }
        
        private function onDoubleClick(evt:MouseEvent):void
        {
            this.deactivate();
            this.isDrawing = false;
            if(this.graphicsLayer.hasEventListener(MouseEvent.DOUBLE_CLICK)) this.graphicsLayer.removeEventListener(MouseEvent.DOUBLE_CLICK,onDoubleClick);
        }
    }
}

[ 本帖最后由 summer521 于 2011-5-27 10:19 编辑 ]

作者: summer521   发布时间: 2011-05-27

怎么都没人帮我看看呢

作者: summer521   发布时间: 2011-05-27