2

ムービークリップであるこのPlayerクラスがあり、幅と高さを設定してからステージに追加しようとしていますが、何らかの理由で、this.widthは0を返し、設定します。サイズは親クラスからのみ機能します。なぜこれが発生するのですか?

public class Player extends MovieClip {

    public var head:MovieClip = new Head_normal_front();

    public function Player(stage:Stage){
        this.addChild(head);
        this.width = 10;
        this.height = 10;
        stage.addChild(this);

    }

}

ありがとう

4

1 に答える 1

7

次のようなものを試してください:

public class Player extends MovieClip {

    public var head:MovieClip = new Head_normal_front();

    public function Player(stage:Stage){
        this.addChild(head);
        this.addEventListener(Event.ADDED_TO_STAGE, onAddedToStage);
        stage.addChild(this);
    }

    private function onAddedToStage(e:Event):void
    {
        this.removeEventListener(Event.ADDED_TO_STAGE, onAddedToStage);
        this.width = 10;
        this.height = 10;
    }
}

ステージに追加した後、表示オブジェクトの幅/高さを変更する必要があります。おそらくstage.addChild(this)もPlayerの外に移動します。

于 2013-03-01T18:29:32.600 に答える