0

嗨,我正在尝试制作一个对象,在本例中为“ship_mc”,移动到屏幕上的 3 个不同点,但我想使用补间类。我不确定为什么它不起作用,任何帮助将不胜感激。我的代码看起来像这样

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

var myTween01:Tween = new Tween(this, "x", Regular.easeIn, 1416, 973, 4, true);
var myTween02:Tween = new Tween(this, "y", Regular.easeIn, 206, 446, 4, true);
var myTween03;
var myTween04;
var myTween05;
var myTween06;


myTween01.addEventListener(TweenEvent.MOTION_FINISH, onFinish);
function onFinish(e:TweenEvent):void {
myTween03:Tween = new Tween(this, "x", None.easeIn, 973, 695, 4, true);
myTween04:Tween = new Tween(this, "y", None.easeIn, 446, 222, 4, true);

}

myTween04.addEventListener(TweenEvent.MOTION_FINISH, onFinish1);
function onFinish1(e:TweenEvent):void {
myTween05:Tween = new Tween(this, "x", None.easeIn, 695, 374, 4, true);
myTween06:Tween = new Tween(this, "y", None.easeIn, 222, 239, 4, true);
}

这是我得到的错误

Symbol 'ship_mc', Layer 'Actions', Frame 1, Line 15 1067: Implicit coercion of a value of type fl.transitions:Tween to an unrelated type Class.
Symbol 'ship_mc', Layer 'Actions', Frame 1, Line 15 1188: Illegal assignment to class Tween.
Symbol 'ship_mc', Layer 'Actions', Frame 1, Line 16 1067: Implicit coercion of a value of type fl.transitions:Tween to an unrelated type Class.
Symbol 'ship_mc', Layer 'Actions', Frame 1, Line 16 1188: Illegal assignment to class Tween.
Symbol 'ship_mc', Layer 'Actions', Frame 1, Line 22 1067: Implicit coercion of a value of type fl.transitions:Tween to an unrelated type Class.
Symbol 'ship_mc', Layer 'Actions', Frame 1, Line 22 1188: Illegal assignment to class Tween.
Symbol 'ship_mc', Layer 'Actions', Frame 1, Line 23 1067: Implicit coercion of a value of type fl.transitions:Tween to an unrelated type Class.
Symbol 'ship_mc', Layer 'Actions', Frame 1, Line 23 1188: Illegal assignment to class Tween.

谢谢,我知道人们会建议使用 tweenlite,但我想知道这里有什么问题,否则我不会学习!

4

1 回答 1

0

您收到的错误消息会告诉您出现问题的行:15、16、22 和 23:

15: myTween03:Tween = new Tween(this, "x", None.easeIn, 973, 695, 4, true);
16: myTween04:Tween = new Tween(this, "y", None.easeIn, 446, 222, 4, true);

22: myTween05:Tween = new Tween(this, "x", None.easeIn, 695, 374, 4, true);
23: myTween06:Tween = new Tween(this, "y", None.easeIn, 222, 239, 4, true);

您的前两个补间代码工作正常,那么前两个补间和其余补间之间的唯一区别是什么?你声明它们的方式。您需要将 、 和 声明myTween03myTween04补间以防止引发错误,因为它认为您正在尝试将默认类初始化为补间myTween05myTween06改变:

var myTween03;
var myTween04;
var myTween05;
var myTween06;

var myTween03:Tween;
var myTween04:Tween;
var myTween05:Tween;
var myTween06:Tween;

并以与第一个和第二个补间相同的方式初始化它们:

myTween03 = new Tween(this, "x", None.easeIn, 973, 695, 4, true);
myTween04 = new Tween(this, "y", None.easeIn, 446, 222, 4, true);

这基本上表明变量将在稍后的代码中初始化为补间,并将防止抛出这些错误。

于 2012-10-25T11:19:40.123 回答