flex实现鼠标跟随十字架
效果图
添加侦听事件
?
canVas.addEventListener(MouseEvent.MOUSE_MOVE,mouseMove);canVas.addEventListener(MouseEvent.CLICK,ShowLabel);?
?
鼠标移动事件
private function mouseMove(event:MouseEvent):void{dataX.x=event.stageX-25;dataX.y=canVasHeight+25;dataY.y=event.stageY;dataY.x=8*itemWidth+50;dataY.visible=true;dataX.visible=true;dataX.text=event.localX.toString();dataY.text=event.localY.toString();//dataY.text=IsXY.toString();canVol.graphics.clear();if(IsXY){ canVol.graphics.lineStyle(1,0xFFFFFF,.5); canVol.graphics.moveTo(0,event.localY); canVol.graphics.lineTo((8*itemWidth),event.localY); canVol.graphics.moveTo(event.localX,0); canVol.graphics.lineTo(event.localX,canVas.height); }}
鼠标单击改变是否显示状态
private function ShowLabel(event:MouseEvent):void{if(IsXY){IsXY=false;}else{IsXY=true;}