About the Height and Width property of DisplayObject
2011-03-12 22:42
567 查看
关于DisplayObject的width和height属性的问题,主要两点记住:
1.当没有使用graphics去绘制内容时, 其width和height一定是0.
2.child DisplayObject对其宽度和高度没有影响。
注意:这里是DisplayObject类和其一些子类。UIComponent并不如此。
There are something to explain about the height and width of DisplayObject.
1: If there is no content in the instance
of DisplayObject(except for TextField), then the height of it will be 0 even
you set it to some non-zero number”:
From the code above, we see that the content is null, so we can see that when we get the height
from this property:height, we get 0. But we should understand what is content?
Some code showing below:
We see that after we use the graphics of the
DisplayObject instance to draw something, the width and height of them is calculated by what the graphics has drawn. What about
the child? What is the impact after we add child to the DisplayObject?
2. About the CONTENT
of the DisplayObject
We see that the child DisplayObject has no impact on the
width and height of the DisplayObject. This means that the height will not calculate
the children nodes of it.
So here we have an conclusion: the height and width of an DisplayObject
is not what it have drawn by itself, in another word: the content of
DisplayObject does not contain the children of it.
3. About the
relation between scaleX and width or scaleY and height
In fact, the
width and height is calculated with the scaleX, scaleY and the real position of
it. We should remember that, after we adjust the width, in fact we have adjust the
scaleX, the scaleX and scaleY is really stored.
1.当没有使用graphics去绘制内容时, 其width和height一定是0.
2.child DisplayObject对其宽度和高度没有影响。
注意:这里是DisplayObject类和其一些子类。UIComponent并不如此。
There are something to explain about the height and width of DisplayObject.
1: If there is no content in the instance
of DisplayObject(except for TextField), then the height of it will be 0 even
you set it to some non-zero number”:
private function testHeight1():void { var shape:Shape = new Shape(); shape.height = 10; trace(shape.height); } Result:0 |
from this property:height, we get 0. But we should understand what is content?
Some code showing below:
private function testHeight2():void { var shape:Shape = new Shape(); // draw a rectangle, topleft corner is (0,0),width and height is 100 shape.graphics.drawRect(0,0,100,100); shape.graphics.drawCircle(100,100, 50); shape.graphics.drawCircle(0,0,50); trace("with content DisplayObject height:"+shape.height); trace("with content DisplayObject width:" +shape.width); } Result: with content DisplayObject height:200 with content DisplayObject width:200 |
DisplayObject instance to draw something, the width and height of them is calculated by what the graphics has drawn. What about
the child? What is the impact after we add child to the DisplayObject?
2. About the CONTENT
of the DisplayObject
private function testHeight3():void { var childShape:Shape = new Shape(); childShape.graphics.drawCircle(0,0,200); var sprite:Sprite = new Sprite(); sprite.height = 20; sprite.width = 20; sprite.addChild(childShape); trace("After add a child, the height is:" + sprite.height); trace("After add a child, the width is:" + sprite.width); } Result: After add a child, the height is:0 After add a child, the width is:0 |
width and height of the DisplayObject. This means that the height will not calculate
the children nodes of it.
So here we have an conclusion: the height and width of an DisplayObject
is not what it have drawn by itself, in another word: the content of
DisplayObject does not contain the children of it.
3. About the
relation between scaleX and width or scaleY and height
In fact, the
width and height is calculated with the scaleX, scaleY and the real position of
it. We should remember that, after we adjust the width, in fact we have adjust the
scaleX, the scaleX and scaleY is really stored.
相关文章推荐
- About the Height and Width property of DisplayObject
- Qt How to get the width and height of a widget
- Its width is W and height is H. As a result, if the font size of characters is S then it can only sh
- The run order about Loaded event and OnApplyTemplate in custom control of Silverlight 2 beta 2
- The usage of the Javascript method call and apply(what is the new and object.create difference.)(What does call(null) mean?)
- Get and display the size of file and directory in Linux system using du command 获取和现实linux文件大小(三)
- About the issue of After delete a record from grid and refresh the datasource, the cursor go to first top record.
- About:How to write the declaration of pointers and references rightly.
- ASP.Net MVC – What are the uses of Display, DisplayName, DisplayFormat and ScaffoldColumn attributes
- About the Rebase and Bind operation in the production of software
- custom format Property of business object for the data binding
- The difference of the type of DB type property such char,varchar,nchar and nvarchar
- The Details About Syntax of gcc as and ld
- THE ENFORCEMENT OF PROPERTY RIGHTS IN CHILDREN, AND THE MARRIAGE CONTRACT
- [Nuxt] Add Arrays of Data to the Vuex Store and Display Them in Vue.js Templates
- Unable to get value of the property '2': object is null or undefined
- CustomPropertyDrawer-Change the height of Property field
- Bob Tarr: Some Object-Oriented Design Principles(1): Minimize The Accessibility of Classes and Members
- the default width and heigth of all the component is 0!!!
- ASP.Net MVC – What are the uses of Display, DisplayName, DisplayFormat and ScaffoldColumn attributes