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

标签 actionscript-3

我有一个 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 之外。

关于actionscript-3 - 在 AS3 中设置动画片段的宽度/高度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15164016/

相关文章:

java - 如何在 Java 或 AS3 中创建和旋转三维矩阵

javascript - jQuery swfobject AS3 ExternalInterface 不工作

html - 使用 Flash AS3 提取 div 的内容

apache-flex - 为什么 FlexUnit 中没有 assertError() 函数?

sql - 优化保存到sqlite数据库?

ios - 需要与 iTunes 共享在 ios-air-app 中创建的文档

flash - "external"swf AS3 中的访问符号

javascript - 使用 firefox 在 mac 上右键单击 flash 应用程序会触发 mousedown

apache-flex - 如何从同时播放的所有声音中获取声音数据? ( ActionScript 闪烁)

actionscript-3 - 同等缩放有边框和无边框 Flash 图形