Flash类的运用:可放大、缩小、旋转的鼠标操作类代码介绍

2019-10-08 12:29:53丽君

gTem.lineTo(arrPoint[2].x, arrPoint[2].y);
//
gTem.moveTo(arrPoint[1].x, arrPoint[1].y);
gTem.lineTo(arrPoint[5].x, arrPoint[5].y);
//
gTem.moveTo(arrPoint[7].x, arrPoint[7].y);
gTem.lineTo(arrPoint[3].x, arrPoint[3].y);
//画旋转的点
//中心点
if(isR){
spCenterPoint=new Sprite();
spCenterPoint.mouseEnabled=false;
spCenterPoint.graphics.beginFill(0xff0000, 0.5);
spCenterPoint.graphics.drawCircle(0, 0, numOpPointWH / 2);
spCenterPoint.graphics.endFill();
spCenterPoint.x=pCent.x;
spCenterPoint.y=pCent.y;
var pTem:Point=currentOp.globalToLocal(pCent);
spParent.addChild(spCenterPoint);
//旋转控制点
spRotationPoint=new Sprite();
spRotationPoint.graphics.beginFill(0xff0000, 0.5);
spRotationPoint.graphics.drawCircle(0, 0, numOpPointWH / 2);
spRotationPoint.graphics.endFill();
spRotationPoint.x=x1 - numOpPointWH;
spRotationPoint.y=y1 - numOpPointWH;
spParent.addChild(spRotationPoint);
spRotationPoint.addEventListener(MouseEvent.MOUSE_DOWN, fun_point_down);
spRotationPoint.addEventListener(MouseEvent.MOUSE_UP, fun_point_up);
}
//
}
public function fun_opUp(e:MouseEvent):void {
isDrogOp=false;
currentOp.stopDrag();
showOp4point(currentOp);
}
//如果isR=false 不可以进行旋转操作
public function fun_opDown(e:MouseEvent,isR:Boolean=true):void {
this.isR=isR
currentOp=e.target as Sprite;
showOp4point(currentOp);
//
currentOp.startDrag();
isDrogOp=true;
}
public function fun_over(e:MouseEvent):void {
var spTem:Sprite=e.target as Sprite;
}
//
//不能越过边界
public function noMoveBorder(rBorder:Rectangle):uint {
var r:Rectangle = currentOp.getBounds(spParent)
var numOffsetTem:Number=10
if(rBorder.width-numOffsetTem<r.width){
currentOp.width=rBorder.width-numOffsetTem
return 0
}
if(rBorder.height-numOffsetTem<r.height){
currentOp.height=rBorder.height-numOffsetTem
return 0
}
//trace(currentOp);
if (r.x<rBorder.x) {
opObject.RegPoint(currentOp, currentOp.globalToLocal(pCent));
no();
currentOp.x=rBorder.x+r.width/2;
}
if (r.y<rBorder.y) {
opObject.RegPoint(currentOp, currentOp.globalToLocal(pCent));
no();
currentOp.y=rBorder.y+r.height/2;
}
if (r.x+r.width>rBorder.x+rBorder.width) {
opObject.RegPoint(currentOp, currentOp.globalToLocal(pCent));
no();
currentOp.x=rBorder.x+rBorder.width-r.width/2;
}
if (r.y+r.height>rBorder.y+rBorder.height) {
opObject.RegPoint(currentOp, currentOp.globalToLocal(pCent));