繁体   English   中英

在AS3中设置动画片段的宽度/高度

[英]Set width/height of a movieclip in AS3

我有一个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);

    }

}

谢谢

尝试类似以下内容:

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之外。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM