[英]as3 get WIDTH and HEIGHT of scaled / resized - movieClip / mc?
[英]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.