Actionscript 3 ActionScript3-如何仅在Tween移动结束后删除
我想要最后一条语句Actionscript 3 ActionScript3-如何仅在Tween移动结束后删除,actionscript-3,Actionscript 3,我想要最后一条语句removeChild(dropBall1)仅在Tween移动结束后执行。我该怎么做?现在就这样,它马上就被移除了 function onClick10f1(e: MouseEvent) { addChild(dropBall1) removeChild(bigBall1) dropBall1.x = 356.10; dropBall1.y = 28; var bigBDrop1: Tween = new Tween(dropBall1, "y", Regular.easeI
removeChild(dropBall1)此脚本中的code>仅在Tween移动结束后执行。我该怎么做?现在就这样,它马上就被移除了
function onClick10f1(e: MouseEvent) {
addChild(dropBall1)
removeChild(bigBall1)
dropBall1.x = 356.10;
dropBall1.y = 28;
var bigBDrop1: Tween = new Tween(dropBall1, "y", Regular.easeIn, 28, 156, 1, true);
removeChild(dropBall1);
你要找的是利用这个班
基本上,对于TweenEvents,您可以在tween的生命周期中选择要做什么。值得注意的是,变量作用域成为侦听器的一个问题。我已经很久没有使用Tween和TweeneEvent类了,因此您可能需要重新构造事件处理程序函数以访问dropBall1
变量,因为我不记得该函数是否可以访问它
试试这个:
function onClick10f1(e:MouseEvent) {
addChild(dropBall1);
removeChild(bigBall1);
dropBall1.x = 356.10;
dropBall1.y = 28;
var bigBDrop1:Tween = new Tween(dropBall1, "y", Regular.easeIn, 28, 156, 1, true);
bigBDrop1.addEventListener(TweenEvent.MOTION_FINISH, onFinish);
}
function onFinish(e:TweenEvent) {
removeChild(dropBall1);
}
还要确保为TweenEvent类添加必要的导入语句:
import fl.transitions.TweenEvent;
Tween
对象发送类型为TweenEvent.MOTION\u FINISH的TweenEvent事件(更准确地说:TweenEvent)。尝试您的建议时,我得到错误:“找不到类型或不是编译时常量:TweenEvent”。我确实有“import fl.transitions.TweenEvent;”更正我没有导入。现在可以了。这为采购订单问题提供了一个解决方案,但通过提供一个有缺陷的代码来解决,这只会让采购订单更加困惑。此代码无法正常工作,因为对象“bigBDrop1”是一个局部变量,最终将被GC调用,导致tween在随机时间停止(或者如果它可以在GC之前完成,则不会停止)。修复该代码,使bigBDrop1无法获取GC。