我是flash actionscript3的初学者,我正在寻找动作脚本的时间可以让我在角落中旋转movieclip,就像任何图像经典旋转一样,边界框出现,没有值,只有手动旋转,我能得到任何帮助吗?
答案 0 :(得分:0)
如果我理解你想要的东西,我会为你写一些代码。将此代码放在第1帧上。对于要旋转的任何图片,请为其指定实例名称并致电makeRotatable(instanceNameOfYourPictureHere)
。
它并不完美,但它可以让你开始。
import flash.display.MovieClip;
import flash.events.MouseEvent;
import flash.display.DisplayObject;
import flash.geom.Rectangle;
//change "myPicture" to any object you want to make rotatable
makeRotatable(myPicture);
var currentObject:Object; //holds a reference to whichever objectis currently being rotated
var oldx:Number;//used to determine mouse movement on every new frame
var oldy:Number;
var boundsRect:Rectangle;//used for creating bounding box
function makeRotatable(target:DisplayObject){//this function sets up the rotation center and adds mouse handling
//creating a container for your picture
var pictureContainer:MovieClip = new MovieClip;
//adding it to the stage
stage.addChild(pictureContainer);
//setting its top left corner, around wich it will rotate, in the center of your picture
pictureContainer.x = target.x + target.width * 0.5;
pictureContainer.y = target.y + target.height * 0.5;
//adding your picture into the container, and moving its center onto the rotational point of the container
pictureContainer.addChild(target);
target.x = 0 - target.width * 0.5
target.y = 0 - target.height * 0.5
//adding mouse listeners to the container and stage
pictureContainer.addEventListener(MouseEvent.MOUSE_DOWN, startRotate)
stage.addEventListener(MouseEvent.MOUSE_UP, stopRotate)
}
function startRotate(e:MouseEvent):void{//sets up for EnterFrame listener and bounding box
stage.addEventListener(Event.ENTER_FRAME, changeRotation)
oldx = stage.mouseX
oldy = stage.mouseY
currentObject = e.currentTarget
boundsRect = currentObject.getBounds(currentObject)
currentObject.graphics.lineStyle(4,0xFF0000);
currentObject.graphics.drawRect(boundsRect.x, boundsRect.y, boundsRect.width, boundsRect.height);
}
function stopRotate(e:MouseEvent):void{//removes EnterFrame listener and bounding box
stage.removeEventListener(Event.ENTER_FRAME, changeRotation)
currentObject.graphics.clear();
}
function changeRotation(e:Event){//rotates the object based on mouse position and movement respective to objects center point
if(stage.mouseX>currentObject.x){
currentObject.rotation += stage.mouseY - oldy
}else{
currentObject.rotation -= stage.mouseY - oldy
}
if(stage.mouseY<currentObject.y){
currentObject.rotation += stage.mouseX - oldx
}else{
currentObject.rotation -= stage.mouseX - oldx
}
oldx = stage.mouseX
oldy = stage.mouseY
}