您好我正在尝试创建一个对象,在本例中为“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,但我想知道这里有什么问题,否则我不会学习!
答案 0 :(得分: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);
前两个补间的代码运行正常,那么前两个和其他补间之间的唯一区别是什么?你宣布他们的方式。您需要声明myTween03
,myTween04
,myTween05
和myTween06
作为补间以防止错误被抛出,因为它认为您尝试将默认类初始化为否则。变化:
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);
这基本上表明变量将在代码中稍后初始化为补间,并将防止抛出这些错误。