开发者

Flash CS4, frame head position following the mouse

I have a small script that moves the frame head backwards and forwar开发者_Go百科ds depending on where my mouseX coordinate is inside the main flash movie. Here's my code and it's working so far:

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

However, when the mouseX cursor leaves the Flash window at x=0, the left edge of the movie, and the mouse reenters the Flash window at stage.stageWidth, the right edge of the movie, the entire movie jumps/jerks to the last framehead.

Now this is sort of what is desired, but I want to soften the effect of moving from ex. frame 0 to frame 30.

So instead of popping to 30, there should be a smooth transition. Can anyone suggest how to manipulate the above function to enable that kind of behaviour!

Thanks in advance!


You could use an easing equation, for example:

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);
}

Or you could even use a tweening engine for a smoother transition...


The final solution:

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));
}

Whew!!!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜