Flash CS4,鼠标跟随鼠标的帧头位置
问题描述:
我有一个小脚本,它根据我的鼠标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,应该有一个平滑过渡。任何人都可以建议如何操纵上述功能来启用这种行为!
在此先感谢!
答
你可以使用一个缓动方程,例如:
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);
}
或者你甚至可以使用渐变发动机的平稳过渡...
答
最终的解决方案:
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));
}
嗖!
我已经发布了我的解决方案作为答案,Cay,你的文章帮了很多!谢谢 – 2009-11-19 05:41:24