Flex:通过导航层次结构访问子项

发布于 2024-11-09 14:49:55 字数 568 浏览 0 评论 0原文

我有一个通用函数来构建控件行(每行包含滑块、单选按钮、重置按钮、文本显示)等,以及一些基于这些控件更改底层数据的功能,

因为我不想为每个控件编写特定代码行,我编写了代码,可以检测到存在鼠标事件的行,尽管该行访问每个单独的控件

使用的层次结构是 titleWindow (弹出窗口的一部分)-> 可换肤容器-> HGroup-> ;control

当我跟踪单选按钮时,我得到的路径如下 Electric_Modify.TitleWindowSkin2620._TitleWindowSkin_Group1.contents.contentGroup.0.RadioButton2645

radioButton 之前的“0”代表第一个 Hgroup id-> 命名为 0

我尝试访问单选按钮如下 - HGroup 中的第 5 个元素 ((this.contentGroup.getChildAt(row)as Group).getChildAt(4) as RadioButton).enabled=false;

并在此行收到消息“无法访问空对象引用的属性或方法”。我应该如何导航层次结构才能到达该元素?

I have a generic function to build rows of controls (each row comprising of sliders, radio buttons, reset buttons, text display) etc, and some functionality to change underlying data based on these

As I didn't want to write specific code for each row, I had code written by which I can detect the row on which there has been a mouseevent, and though the row access each individual control

The hierarchy used is titleWindow (part of popup)->skinnable container->HGroup->control

When I trace for a radiobutton, I get the path as follows Electric_Modify.TitleWindowSkin2620._TitleWindowSkin_Group1.contents.contentGroup.0.RadioButton2645

The '0' before the radioButton stands for the first Hgroup id->named as 0

I tried accessing the radio button as follows- 5th element in the HGroup
((this.contentGroup.getChildAt(row)as Group).getChildAt(4) as RadioButton).enabled=false;

and get a message "Cannot access a property or method of a null object reference" on this line. How should I navigate the hierarchy to reach the element?

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

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

发布评论

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

评论(2

青丝拂面 2024-11-16 14:49:55

您应该使用 getElementAt(...) 而不是 getChildAt(...)。

获取元素函数代表“更高级别”的元素层次结构,这是使换肤更容易所必需的。

((this.getElementAt(row) as IVisualElementContainer).getElementAt(4) as RadioButton).enabled = false;

它应该看起来像这样,但确切的层次结构取决于您的应用程序中的内容。

You should be using getElementAt(...) and not getChildAt(...).

The get element functions represent a "higher level" element hierarchy which is needed to make skinning easier.

((this.getElementAt(row) as IVisualElementContainer).getElementAt(4) as RadioButton).enabled = false;

It should look something like that, but the exact hierarchy depends on what's in your app.

云仙小弟 2024-11-16 14:49:55

@drkstr

感谢您的输入...我想到了一种对我有用的替代方法...我通过

parent1=hgrp.parent映射出了HGroup的父级;然后按如下方式引用这些按钮

((parent1.getChildAt(row)as Group).getChildAt(4) as RadioButton)

这就像一个梦想......我想你的建议会让我跳过中间层

@J_A_X/@康斯坦丁:谢谢你的建议。我不知道为什么我们没有仔细思考并沿着数据组的道路走下去。乍一看似乎更简单...我们必须在 MXML 中创建 UI 控件,并连续布置控件,而当要使其通用时,我们实际上在 AS 中复制了 MXML 方法。一开始很容易,直到出现上述问题。当我们升级版本时,我们将通过更好的方法解决这个问题。目前有效

@drkstr

Thanks for your input... I thought of an alternate approach that worked for me...I mapped out the parent of the HGroup via

parent1=hgrp.parent; and then referenced these buttons as follows

((parent1.getChildAt(row)as Group).getChildAt(4) as RadioButton)

This works like a dream...I presume your suggestion would let me jump across the intermediate layers

@J_A_X/ @Constantiner: Thanks for the suggestion. I have no idea why we didn't think through and go down the DataGroup path. Prima facie seems simpler... we got to creating the UI controls in MXML laying out controls serially,and when it came to making it generic, we literally replicated the MXML approach in AS. Started off easy, till it caused problems like above. We will fix this to a better approach, when we upgrade versions. It works for now

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