开发者

Why are my component's unscaled width/height zero?

开发者 https://www.devze.com 2022-12-21 09:29 出处:网络
Why ar开发者_Go百科e unscaledWidth and unscaledHeight tracing to 0 when the calling component doesn\'t explicitly set a width and height?(If calling component does set width and height, they are traci

Why ar开发者_Go百科e unscaledWidth and unscaledHeight tracing to 0 when the calling component doesn't explicitly set a width and height? (If calling component does set width and height, they are tracing to the set value.) Shouldn't measure() force the minimum width and height?

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);
    }
}
}

More info: The properties are tracing to 0 when called from a .as file. When called from a .mxml file they are appearing fine.

Calling code (from both .as and .mxml - as shows 0,0, mxml shows 400,75):

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

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

精彩评论

暂无评论...
验证码 换一张
取 消