AS3将MovieClip传递给super

发布于 2024-12-09 09:17:57 字数 445 浏览 0 评论 0原文

我有一个宇宙飞船 movieclip,里面有一个movieclip 炮塔

Spaceship 扩展 Unit 类,我想在其中旋转炮塔。

在我的 Spaceship 构造函数中,我使用 super(this.turret); ,但这始终返回 null 。

传递其他变量是可行的,并且在调用 super() 之前,我可以成功跟踪 this.turret

那为什么我不能将其传递给 super 呢?我该如何解决这个问题?

[编辑] 也许这与调用 super() 时炮塔不可用/添加到舞台有关?如果是这样,我该如何处理并得到它“单位”呢?

I have a Spaceship movieclip, with a movieclip Turret inside.

Spaceship extends the Unit class, where I want to rotate the Turret.

In my Spaceship constructor, I use super(this.turret); but this always returns null.

Passing other variables works, and before calling super(), I can successfully trace this.turret

So why can't I pass it to super? And how can I fix this?

[edit]
Perhaps it has something to do with the turret not being available/added to stage yet when super() is called? If so, how could I deal with that and get it "Unit" anyways?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

杀お生予夺 2024-12-16 09:17:57

当您将 turret 传递到 构造函数 时,您只是传递对具有该实例名称的 MovieClip 的引用。 Unit 构造函数 对参数做什么?我猜你的 Unit 类不应该有炮塔变量。

更新1:

public class SpaceShip extends Unit
{

    public var turret : MovieClip;

    public function SpaceShip()
    {
        super();
    }

}

// Access from other class where ship has been referenced
public class Test extends Sprite
{

    public var ship : SpaceShip;

    public function ship()
    {
        // access the public variable (reference) turrent
        ship.turrent.rotation += 25;
    }

}

When you pass turret into the constructor you are only passing a reference to the MovieClip with that instance name. What does the Unit constructor do with the parameter? I guess that your Unit class are not supposed to have a turret variable.

UPDATE 1:

public class SpaceShip extends Unit
{

    public var turret : MovieClip;

    public function SpaceShip()
    {
        super();
    }

}

// Access from other class where ship has been referenced
public class Test extends Sprite
{

    public var ship : SpaceShip;

    public function ship()
    {
        // access the public variable (reference) turrent
        ship.turrent.rotation += 25;
    }

}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文