我是一个闪光灯actionscript3的初学者,我一直在寻找一个动作脚本,可以让我在它的中心旋转电影,就像任何图像的经典旋转一样,出现了包围框,没有值,只有手动旋转,我能得到任何帮助吗?
发布于 2014-11-09 20:16:02
我给你写了一些代码,如果我正确理解了你想要的。将此代码放在框架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
}https://stackoverflow.com/questions/26824252
复制相似问题