在AS3一个影片剪辑的设置宽/高 [英] Set width/height of a movieclip in AS3

查看:193
本文介绍了在AS3一个影片剪辑的设置宽/高的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个影片剪辑这个播放器类, 我试图设置它的宽度和高度,从它,然后使其自身添加到舞台, 但由于某些原因,无论我做什么,this.width返回0,设置大小只从父类的工作。为什么会出现这种情况?

I have this Player class which is a movieclip, I'm trying to set it's width and height from it and then make it add itself to the stage, But for some reason, no matter what I do, this.width returns 0 and setting the size only works from the parent class.. why is this happening?

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播放器(这)之外了。

You should modify the width/height of display objects after they are added to the stage. I would probably move the stage.addChild(this) outside of Player too.

这篇关于在AS3一个影片剪辑的设置宽/高的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆