获取动态创建的自定义 uicomponent 的宽度

发布于 2024-07-27 12:01:58 字数 406 浏览 5 评论 0原文

我有一些源自 UIComponent 的自定义组件。 我重载了 updateDisplayList,因此它们具有自定义外观。 我创建了一个布局器来布置这些自定义组件,但为了正确放置它们,我必须知道自定义组件的宽度和高度。 它们是动态创建的。 创建完所有这些之后(每个都会触发creationCompleted事件),我尝试对它们进行布局,但宽度/高度属性仍然是0。 在布局过程之前,我还尝试将它们添加到画布中。

所以我的问题是,如何创建动态放置的自定义 UIComponent,并了解它的宽度和高度。

谢谢


编辑:

通过使用 mx_internal 命名空间,我可以设置宽度和高度(使用内部 $width 和 $height 字段),并且看起来它正在工作。 但不是那么干净/好的解决方案。

I have some custom components, that derived from UIComponent. I overloaded the updateDisplayList so they have custom look. I've created a layouter that lays out these custom components, but to place them correctly, I have to know the custom componets width, height. They are created dynamically. After all of them created (creationCompleted event fired for every), i try to laying out them, but width/height property is still 0.
I am also tried to add them to a canvas, before the layout process.

So my question is, how to create custom UIComponent that placed dynamically, and get to know the width and height of it.

thanks


edit:

With the use of the mx_internal namespace I can set width and height (using the internal $width and $height fields), and it looks like it is working. But not so clean/good solution.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

等数载,海棠开 2024-08-03 12:01:58

如果您从 UIComponent 继承,而不是从其子类之一继承,那么您可能需要确保实现了measure() 方法等。 请查看此处的 Flex 文档,了解有关实现您自己的 UIComponent 的更多信息——这里有大量信息可供阅读,但如果您直接从 UIComponent 派生,这些都是您可能应该知道的内容:

http://www.adobe.com/livedocs/flex/3/html /help.html?content=ascomponents_advanced_3.html

希望有帮助! 您也可以尝试发布一些代码,以便我们有更具体的内容可以继续。 但很可能,您只是没有实现应该执行的操作来检索这些值。 (你的直觉是正确的——你不应该为了得到你需要的东西而深入研究 mx_internal 。)

If you're inheriting from UIComponent, rather than from one of its subclasses, you'll probably want to make sure you're implementing the measure() method, among others. Check out the Flex docs here for more information on implementing your own UIComponents -- there's a good bunch of info to read here, but it's all stuff you should probably know if you're deriving from UIComponent directly:

http://www.adobe.com/livedocs/flex/3/html/help.html?content=ascomponents_advanced_3.html

Hope it helps! You might also try posting a little code, just so we have something more specific to go on. But chances are, you're just not implementing something you should be in order to retrieve those values. (And your instinct is correct -- you shouldn't have to dig into mx_internal in order to get what you need.)

会发光的星星闪亮亮i 2024-08-03 12:01:58

也许这有效?

component.getExplicitOrMeasuredWidth() 
component.getExplicitOrMeasuredHeight()

Maybe this works?

component.getExplicitOrMeasuredWidth() 
component.getExplicitOrMeasuredHeight()
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文