我试图利用AS3将对象添加到舞台上。据我所知,使用新的Adobe Animate,使用Sprit可以比使用MC更有效率,所以我试图弄清楚它是如何完成的,我一直在寻找只涉及MC而不是精灵的旧教程,本身。因此,我们非常感谢使用精灵的任何有用信息。
现在,我的具体的问题是:
package
{
import flash.display.Sprite
public class Ship extends Sprite
{
public function addShip():void
{
trace("addShip function run");
}
}
}
这是一个名为Ship.as的文件,我已将其链接到文件菜单下的Actionscript Settings菜单中的文件Ship.fla。 然后,在我的Ship.fla文件中,主时间轴的第一帧有:
ShipMc:Ship = new Ship();
addEventListener(MouseEvent.CLICK, addShip);
给出了这些错误:
1067: Implicit coercion of a value of type Ship to an unrelated type Class.
1188: Illegal assignment to class Ship.
1120: Access of undefined property addShip.
答案 0 :(得分:1)
可能缺少var吗?正确的代码应该是:
stop();//if you are adding things on timeline, and in case you have more then 1 frame
var ShipMc:Ship = new Ship();
addChild(ShipMc);
addEventListener(MouseEvent.CLICK, ShipMc.addShip); //this makes the whole stage clickable
//ShipMc.addEventListener(MouseEvent.CLICK, addShip) - in case you want only the ship to be clickable