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 开发者_StackOverflowto 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;
}
}
加载中,请稍侯......
精彩评论