Flex 中文本的高度
如何获取从 ActionScript 动态创建的 Text 组件的高度。例如,如果您有类似的问题:
var temp:Text = new Text;
temp.width = 50;
temp.text = "Simple text";
如何获取温度高度?
How can you get the height of the Text component that's been created dynamically from ActionScript. For instance, if you have something like:
var temp:Text = new Text;
temp.width = 50;
temp.text = "Simple text";
how to get height of temp?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以调用 validateNow() 以确保应用样式(以及相关的高度)
You can call validateNow() to make sure the style is applied (and the height relevant)
跟踪(温度.高度);
根据评论进行编辑:
好的,我明白为什么了,因为您依赖于默认高度,所以在 UI 绘制控件之前,控件没有高度属性,因此您无法返回它,直到添加到父对象后。因此,当您单击文本时,这个简单的应用程序将返回 22:
但这只是因为在绘制项目之后我才尝试获取高度。
或者根据 user294702 所说的进行构建:这也有效。
我希望您喜欢今天的 UI 课程,我不能接受提示,但请对我的评估或建设性批评给予积极的结果。 :-)
trace(temp.height);
Edit Based on Comments:
OK I see why, because you are relying on a default height, the Control does not have a height property until the UI draws it so you wouldn't be able to return it until after it's added to the parent object. so this simple app will return 22 when you click on the text:
But that's only because I'm not trying to get the height until well after the item has been drawn.
OR building off what user294702 said: This works too.
I hope you've enjoyed your UI lesson today, I can't accept tips but please give positive results on my evaluation or constructive criticism. :-)