我试图在鼠标点击上补间影片剪辑的位置。到目前为止,我有这个代码
import fl.transitions.Tween;
import fl.transitions.easing.*;
var posY:Number = infographic_mc.y
var redY:Number = -232
var orangeY:Number = -551
var yellowY:Number = -883
var greenY:Number = -1225
var blueY:Number = -1543
var purpleY:Number = -1873
var tween1:Tween = new Tween(infographic_mc, "y", Regular.easeOut, posY, redY, 2, true);
var tween2:Tween = new Tween(infographic_mc, "y", Regular.easeOut, posY, orangeY, 2, true);
var tween3:Tween = new Tween(infographic_mc, "y", Regular.easeOut, posY, yellowY, 2, true);
var tween4:Tween = new Tween(infographic_mc, "y", Regular.easeOut, posY, greenY, 2, true);
var tween5:Tween = new Tween(infographic_mc, "y", Regular.easeOut, posY, blueY, 2, true);
var tween6:Tween = new Tween(infographic_mc, "y", Regular.easeOut, posY, purpleY, 2, true);
tween1.stop();
tween2.stop();
tween3.stop();
tween4.stop();
tween5.stop();
tween6.stop();
red_btn.addEventListener(MouseEvent.CLICK, redButtonClick);
orange_btn.addEventListener(MouseEvent.CLICK, orangeButtonClick);
yellow_btn.addEventListener(MouseEvent.CLICK, yellowButtonClick);
green_btn.addEventListener(MouseEvent.CLICK, greenButtonClick);
blue_btn.addEventListener(MouseEvent.CLICK, blueButtonClick);
purple_btn.addEventListener(MouseEvent.CLICK, purpleButtonClick);
function redButtonClick(event:MouseEvent):void {
tween1.start();
}
function orangeButtonClick(event:MouseEvent):void {
tween2.start();
}
function yellowButtonClick(event:MouseEvent):void {
tween3.start();
}
function greenButtonClick(event:MouseEvent):void {
tween4.start();
}
function blueButtonClick(event:MouseEvent):void {
tween5.start();
}
function purpleButtonClick(event:MouseEvent):void {
tween6.start();
}
这有效,但它不会在补间之后存储Y坐标,并且每个补间都会回到开头。
有没有办法在mouseClick函数中更新存储Y坐标的变量?
答案 0 :(得分:0)
您可以使用变量来存储当前补间,而不是在开头创建所有补间。
var currentTween:Tween;
然后在每个事件侦听器中,您可以根据infographic_mc当前位置创建当前补间。代码看起来像这样:
function redButtonClick(event:MouseEvent):void {
if(currentTween) currentTween.stop(); //if there is a current tween animating, stop it
currentTween = new Tween(infographic_mc, "y", Regular.easeOut, infographic_mc.y, redY, 2, true);
currentTween.start();
}
另外,我建议为所有按钮而不是单独的函数使用一个处理函数,并使用switch语句来确定单击了哪个按钮。此外,如果您计划在应用程序中使用大量动画,请查看GreenSock库以进行补间,因为它具有更好的性能。