2014-11-09 58 views
0

我是一個flash actionscript3的初學者,我正在尋找一個動作腳本的小時,可以讓我旋轉動畫片段的中心像任何圖像經典旋轉的角落,邊框出現,和沒有價值,只有手動旋轉,我可以得到任何幫助嗎?控制旋轉邊框閃光燈AC3

回答

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 
} 
+0

哇,這太神奇了,它的工作,非常感謝你:) Scab – Sam 2014-11-13 08:49:08