flex的事件响应体会4--degrafa绘图的事件机制探索

继续体会1中的目标
移动canvas上的多个surface中的一个,通过eventcanvas调用testmouseevent。只有当鼠标按在“动”字上,或按在矩形框上才能触发鼠标的MouseEvent.MOUSE_DOWN事件,按在surface的任何空白处都没有作用。继续探索在surface上任意位置 按下鼠标如何响应事件......
testmouseevent.as代码如下

package eventtest
{

       import com.degrafa.GeometryGroup;
       import com.degrafa.GraphicText;
       import com.degrafa.Surface;
       import com.degrafa.geometry.RegularRectangle;
       import com.degrafa.paint.SolidStroke;
      
       import flash.events.MouseEvent;
       import flash.geom.Matrix;
       import flash.geom.Point;
       import mx.controls.Alert;
public class testmouseevent extends Surface
{
[Bindable]
    public var WhiteStroke:SolidStroke = new SolidStroke();
protected var eachcolggw:GeometryGroup = new GeometryGroup();//每个列都需要一个gg,一个边框矩形
    protected var eachcolrecw:RegularRectangle;
private var isMouseDown:Boolean = false;

       private var frompoint:Point=new Point;
       private var topoint:Point =new Point;
public function testmouseevent()
{
                        super();
                    addEventListener(MouseEvent.MOUSE_DOWN, OnMouseDown);
                    addEventListener(MouseEvent.MOUSE_OUT, onMouseOut);
                    addEventListener(MouseEvent.MOUSE_MOVE, OnMouseMove);
/*                     addEventListener(MouseEvent.MOUSE_UP, OnMouseUp);
                    addEventListener(MouseEvent.MOUSE_OVER, onMouseIn); */
        }
     public function  loadevent():void
      {
      eachcolggw.x = 0;
        eachcolggw.y = 10;
        eachcolggw.height=1000;
        eachcolrecw= new RegularRectangle(0, 0,100, 1000);
        eachcolrecw.stroke = WhiteStroke;
        eachcolggw.geometryCollection.addItem(eachcolrecw);
        var gt:GraphicText=new GraphicText;
        gt.text='动';
        gt.x=0;
        gt.y=2;
        eachcolggw.addChild(gt);
        eachcolggw.target = this;
         eachcolggw.addEventListener(MouseEvent.CLICK,this.ggclick);
/*         eachcolggw.addEventListener(MouseEvent.MOUSE_OVER,this.onMouseIn);
        eachcolggw.addEventListener(MouseEvent.MOUSE_OUT,this.onMouseOut);  */
      }   
public function ggclick(event:MouseEvent):void
{
Alert.show("click gg");

}
    //鼠标移动响应事件
   public function OnMouseMove(event:MouseEvent):void
    {
        //如果鼠标左键按下
     if (isMouseDown)
        {
            //计算移动距离并更新矩阵
            topoint.x= event.stageX;
            topoint.y= event.stageY;
            var finalm:Matrix= new Matrix;
            finalm.tx = topoint.x; //- frompoint.x;
            finalm.ty =  topoint.y; //- frompoint.y;
            this.transform.matrix=finalm;
           
         trace(finalm.tx);
        }
        //trace("MOUSE move surface");
        trace("MOUSE move surface");
    }
    //鼠标抬起响应事件
    public function OnMouseUp(event:MouseEvent):void
    {
        //如果鼠标左键按下
      if (isMouseDown)
        {
            topoint.x= event.stageX;
            topoint.y= event.stageY;
            isMouseDown = false;
           trace(topoint.x);
         
           //Alert.show(topoint.x.toString());
        }
         trace("MOUSE up surface");
    }
        protected function onMouseIn(even:MouseEvent):void
    {
//          if(even.currentTarget is GeometryGroup)
            if(even.currentTarget is Surface)
             WhiteStroke.color=0x00ff00;
    }

    protected function onMouseOut(even:MouseEvent):void
    {    
//          if(even.currentTarget is GeometryGroup)
           if(even.currentTarget is Surface)
             WhiteStroke.color=0x000000;
    }
        private function OnMouseDown(event:MouseEvent):void {
                trace("MOUSE DOWN surface");
               // Alert.show("MOUSE DOWN surface");
          isMouseDown = true;
            frompoint.x=event.stageX;
            frompoint.y=event.stageY;
           trace(frompoint.x);
        }
}
}

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