开发者

Flex: accessing child through navigating the hiererachy

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 开发者_JAVA百科null object reference" on this line. How should I navigate the hierarchy to reach the element?


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.


@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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜