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);
}
}
精彩评论