2009-11-18 95 views
1

我有一個小腳本,它根據我的鼠標X座標位於主Flash影片內的哪個位置來前後移動幀頭。這裏是我的代碼,它的工作至今:Flash CS4,鼠標跟隨鼠標的幀頭位置

function onEnterFrame(event:Event):void 
{ 
    var frame:Number = Math.round(mouseX/(stage.stageWidth/animation.totalFrames)); 
    animation.gotoAndStop(frame); 
} 

然而,當mouseX光標離開在x = 0的閃存窗口,電影的左邊緣,並且鼠標在stage.stageWidth重新進入的Flash窗口,電影的右邊緣,整個電影跳到最後的幀頭。

現在,這是什麼是理想的,但我想軟化從前例移動的影響。幀0到幀30.

因此,不應該彈出到30,應該有一個平滑過渡。任何人都可以建議如何操縱上述功能來啓用這種行爲!

在此先感謝!

回答

2

你可以使用一個緩動方程,例如:

var finalFrame:uint=0; 
function onEnterFrame(event:Event):void { 
    var frame:Number = Math.round(mouseX/(stage.stageWidth/animation.totalFrames)); 
    finalFrame+=(frame-finalFrame)*0.2; //simple easing 
    animation.gotoAndStop(finalFrame); 
} 

或者你甚至可以使用漸變發動機的平穩過渡...

+0

我已經發布了我的解決方案作爲答案,Cay,你的文章幫了很多!謝謝 – 2009-11-19 05:41:24

1

最終的解決方案:

function onEnterFrame(event:Event):void 
{ 
    var frame:Number = mouseX/(stage.stageWidth/animation.totalFrames); 
    var newFrame:Number = animation.currentFrame + ((frame - animation.currentFrame)/3); 
    animation.gotoAndStop(Math.round(newFrame)); 
} 

嗖!