当前位置: 动力学知识库 > 问答 > 编程问答 >

actionscript 3 - AS3 pass MovieClip to 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?

网友答案:

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;
    }

}
分享给朋友:
您可能感兴趣的文章:
随机阅读: