2014-02-14 35 views
0

我在舞臺上有一個叫做circle的按鈕。當鼠標移動時,圓圈指向鼠標。這是我用來做circle點鼠標功能:旋轉屬性問題

stage.addEventListener(MouseEvent.MOUSE_MOVE, followTheMouse); 

function followTheMouse(e:MouseEvent):void { 
    circle.rotation = Math.atan2(mouseY-circle.y, mouseX-circle.x)*180/Math.PI + 90; 
} 

circle被點擊時,傳統補間扮演移動circle出舞臺:

circle.addEventListener(MouseEvent.MOUSE_UP, enterZone); 

function enterZone(e:MouseEvent):void { 
    this.play(); 
    stage.removeEventListener(MouseEvent.MOUSE_MOVE, followTheMouse); 
} 

有沒有任何編譯錯誤或運行時錯誤。但是,當我點擊circle時,它不會離開舞臺。

經過一番研究,我發現旋轉屬性會導致經典補間和補間動畫被忽略。爲什麼會發生這種情況,我該如何解決這個問題?

回答

0

經過一番嘗試,我設法解決了這個問題。

我所做的就是製作一個新的關鍵幀,並在其中放置一個按鈕的副本,但沒有實例名稱。這樣,旋轉屬性將不會被定義,並且補間程序正常工作,因爲奇怪的是,動畫片段圖形屬性似乎取消或忽略使用Flash製作的補間。

0

適合我。你甚至可以離開MOUSE_MOVE事件,它在補間過程中起作用。

import flash.display.Sprite; 
import fl.transitions.Tween; 
import fl.transitions.easing.*; 

addEventListener(Event.ENTER_FRAME, loaderCheck); 

function loaderCheck(e:Event):void { 
    // Make sure we have a populated loader by referencing one of its properties. 
    var answer:Boolean; 
    try { answer = (this.loaderInfo.width > 0) ? true : false;} catch (e:Error) {} 
    if (answer == true) { 
     removeEventListener(Event.ENTER_FRAME, loaderCheck); 
     createCircle() 
    } 
} 

var circle:Sprite; 
function createCircle():void { 
    circle = new Sprite(); 
    circle.graphics.beginFill(0xFF0000); 
    circle.graphics.drawCircle(0, 0, 30); 
    circle.graphics.drawRect(0, -30, 2, 30); 
    circle.graphics.endFill(); 
    addChild(circle); 
    circle.x = loaderInfo.width/2; 
    circle.y = loaderInfo.height/2; 
    stage.addEventListener(MouseEvent.MOUSE_MOVE, followTheMouse); 
    circle.addEventListener(MouseEvent.MOUSE_UP, enterZone); 
} 

function followTheMouse(e:MouseEvent):void { 
    circle.rotation = Math.atan2(mouseY-circle.y, mouseX-circle.x)*180/Math.PI + 90; 
} 

function enterZone(e:MouseEvent):void { 
    //stage.removeEventListener(MouseEvent.MOUSE_MOVE, followTheMouse); 
    var myTween:Tween = new Tween(circle, "x", Elastic.easeOut, 0, 300, 3, true); 
} 
+0

'circle'是放置在舞臺上的經典補間的MovieClip。 AS3代碼無論是補間還是「圈子」。 – Yonic