I am new to Flash and ActionScript, but am pretty good at handling. One thing that constantly bothers me is properties widthand height DisplayObject(Container)s. I finally started hugging them and found out that the width and height are Spritedetermined solely by their contents, for example.
I do not understand the following: I have Spriteone that I am adding to the Buttonto group . All buttons have heightfrom 30 and yfrom 0. Thus, I would expect that the heightcontaining Spritewill be 30. Surprisingly, it heightis 100.
Adobe documentation for the properties heightin the DisplayObjectstates:
Indicates the height of the display object in pixels. The height is calculated based on the boundaries of the contents of the displayed object.
Apparently, the "boundaries" of the object are important. So I went ahead and wrote this little test in Sprite, which contains Buttons:
for (var i:int = 0; i < numChildren; ++i)
{
trace("Y: " + getChildAt(i).y + " H: " + getChildAt(i).height);
trace("BOUNDS H: " + getChildAt(i).getBounds(this).height);
}
trace("SCALEY: " + scaleY + " TOTAL HEIGHT: " + height);
This code iterates over all objects added to its display list, and shows their values y, heightand getBounds().height. Amazing output:
Y: 0 H: 30
BOUNDS H: 100
... (5x)
SCALEY: 1 TOTAL HEIGHT: 100
This shows that the borders of the buttons are actually greater than their height (and the height, which is apparently visual). I do not know why this is so. So my questions are:
- Why are the borders of my buttons greater than their height?
- ,
Sprite ,
,
?
, :
var control:Button = new Button();
control.setSize(90, 30);
addChild(control);