Tween事件监听器

时间:2014-01-20 04:39:56

标签: actionscript-3

在一个帧脚本中,我有一个事件监听器,当补间动作结束时,它应该调用'onFinish'函数。 (参见下面红色的相关部分。)我从未看到'完成补间'输出。它无声地失败了。我在不同的地方尝试过addEventListener但无济于事。我错过了什么? 谢谢!

import fl.transitions.*; 
import fl.transitions.easing.*;
import fl.transitions.Tween; 
import fl.transitions.TweenEvent;

var currentFrameMC = animImg; 

var scaleXTween:Tween=new Tween(animImg,"scaleX",Bounce.easeOut, 1,2,2.4,true);
var scaleYTween:Tween=new Tween(animImg,"scaleY",Bounce.easeOut, 1,2,2.4,true);
var alphaTween:Tween = new Tween(animImg, "alpha", Strong.easeOut, .5, 1, 11, true);

//Put a listener on the MC so I can tell when it's done tweening the scale.
currentFrameMC.addEventListener(TweenEvent.MOTION_FINISH, onFinish);


//This is another event listner put on a button:
//(The button, when clicked, will trigger the shrinking of the animImg MC)
reverseTween1.addEventListener(MouseEvent.CLICK,shrinkFrameMC);

//Shrink/scale down the anImg by tweening
function shrinkFrameMC(e:MouseEvent)  //This scales down the playing movie clip
{  
scaleXTween=new Tween(currentFrameMC,"scaleX",None.easeNone, currentFrameMC.scaleX,1,3,true);
scaleYTween=new Tween(currentFrameMC,"scaleY",None.easeNone, currentFrameMC.scaleY,1,3,true);
//Tween the alpha state of the movie clip again, this time in reverse
alphaTween=new Tween(currentFrameMC, "alpha", Strong.easeOut, 1, .5, 11, true);
}

function onFinish(e:TweenEvent):void //This does an action when the frame MC is done tweening
{ 
   trace ("done tweening" );
   //NEVER SEE THIS OUTPUT
}

2 个答案:

答案 0 :(得分:0)

您需要将Tween事件侦听器分配给Tween,而不是要补间的对象。

答案 1 :(得分:0)

它的工作:

import fl.transitions.*; 
import fl.transitions.easing.*;
import fl.transitions.Tween; 
import fl.transitions.TweenEvent;

var scaleXTween:Tween=new Tween(animImg,"scaleX",Bounce.easeOut, 1,2,2.4,true);
var scaleYTween:Tween=new Tween(animImg,"scaleY",Bounce.easeOut, 1,2,2.4,true);
var alphaTween:Tween = new Tween(animImg, "alpha", Strong.easeOut, .5, 1, 11, true);

//Put a listener on the MC so I can tell when it's done tweening the scale.
scaleXTween.addEventListener(TweenEvent.MOTION_FINISH, onFinish);


//This is another event listner put on a button:
//(The button, when clicked, will trigger the shrinking of the animImg MC)
reverseTween1.addEventListener(MouseEvent.CLICK,shrinkFrameMC);

//Shrink/scale down the anImg by tweening
function shrinkFrameMC(e:MouseEvent)  //This scales down the playing movie clip
{  
    scaleXTween=new Tween(currentFrameMC,"scaleX",None.easeNone, currentFrameMC.scaleX,1,3,true);
    scaleYTween=new Tween(currentFrameMC,"scaleY",None.easeNone, currentFrameMC.scaleY,1,3,true);
//Tween the alpha state of the movie clip again, this time in reverse
    alphaTween=new Tween(currentFrameMC, "alpha", Strong.easeOut, 1, .5, 11, true);
}

function onFinish(e:TweenEvent):void //This does an action when the frame MC is done tweening
{ 
   trace ("done tweening" );
   //NEVER SEE THIS OUTPUT
}