为什么我的组件的未缩放宽度/高度为零?

时间:2010-02-25 08:54:16

标签: actionscript-3 actionscript custom-component

当调用组件未明确设置宽度和高度时,为什么unscaledWidth和unscaledHeight跟踪为0? (如果调用组件确实设置宽度和高度,它们将跟踪到设定值。)不应该测量()强制最小宽度和高度?

package {
import flash.display.Graphics;

import mx.core.UIComponent;

public class ToolBar extends UIComponent {
    public function ToolBar() {
        super();    
    }

    override protected function createChildren():void {
        super.createChildren();

    }

    override protected function measure():void {
        super.measure();

        measuredHeight = 400;
        measuredWidth = 75;
        measuredMinHeight = 400;
        measuredMinWidth = 75;
    }

    override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void {
        super.updateDisplayList(unscaledWidth,unscaledHeight);

        var g:Graphics = graphics;
        g.clear();
        g.beginFill(0xfff00f);
        g.drawRect(0,0,unscaledWidth,unscaledHeight);
        g.endFill();

        trace(unscaledWidth + " " + unscaledHeight);
    }
}
}

更多信息:从.as文件调用时,属性将跟踪为0。从.mxml文件调用时,它们看起来很好。

调用代码(来自.as和.mxml - 显示为0,0,mxml显示为400,75):

override protected function createChildren():void {
        super.createChildren();

        if (!toolBar) {
            toolBar = new ToolBar();
            addChild(toolBar);
        }
    }

0 个答案:

没有答案