开发者

How to reach elements of an inline component in flex?

I have a problem with inline components. I want to reach an inline component from another one.. From the first component, i want to change "enable" value of the linkbutton named "Add" which is in second component. Altough i gave "id" and "className" to second one, i could reach neither it nor its elements.. is there a way to do this?

*in first component there is a text input in "CodedDescriptionItemEditor" component. I want to validate it and according to validation enable the button that i mentioned above..

These all are in a datagrid by the way. In datagrid, there is always a row that you can enter data and via the "Add" button you can save it. After save it seems as text..

Thank you..

Here is my code:

<mx:columns>
        <mx:DataGridColumn headerText="{Problem}" wordWrap="true" textAlign="left" sortable="false">
            <mx:itemRenderer>
                <mx:Component>
                    <mx:VBox>
                        <mx:ViewStack selectedIndex="{outerDocument.index(data)}" >
                            <mx:HBox>
                                <mv:CodedDescriptionItemEditor id="editor" codePM="{outerDocument.problemListPanelPM.getProblemDescPM(data)}" 
                                    width="100%" styleName="phrFormItemInput"/>
                            </mx:HBox>
                            <mx:HBox>
                                <mv:CodedDescriptionItemRenderer id="renderer" codedDescPM="{outerDocument.problemListPanelPM.getProblemDescPM(data)}" />
                            </mx:HBox>  
                        </mx:ViewStack> 
                    </mx:VBox>
                </mx:Component>
            </mx:itemRenderer>
        </mx:DataGridColumn>
        <mx:DataGridColumn headerText="" textAlign="center" editable="false" width="50" resizable="false" sortable="false">
            <mx:itemRenderer>
                <mx:Component className="buttonColumn">
                        <mx:ViewStack selectedIndex="{outerDocument.index(data)}" >
                            <mx:HBox horizontalAlign="center" width="100%">
                                <mx:LinkButton id="Add" icon="@Embed('img/add.png')"
                                   开发者_Python百科 toolTip="{outerDocument.Add_Problem}"
                                    click="outerDocument.addHandWritten()"
                                    enabled="false" />
                            </mx:HBox>
                            <mx:HBox horizontalAlign="center" width="100%">
                                <mx:LinkButton id="Delete" icon="@Embed('img/delete.png')"
                                    toolTip="{outerDocument.Remove_problem}"
                                    click="outerDocument.removeProblem()"/>
                            </mx:HBox>
                        </mx:ViewStack>                     
                </mx:Component>
            </mx:itemRenderer>                          
        </mx:DataGridColumn>
    </mx:columns>


Inline components in MXML are not instances but classes. So that kind of "reaching" has no sense. To combine this knowledge together to operate them I recommend you the following simple rule (which I follow and haven't problems with understanding class/instances relations):

Do not use inline components in MXML excluding simple cases on a prototyping stage.

So in your case I recommend you to extract inline components into separate MXML classes and throw all the outerDocument references (you can replace them with events with bubbling). After that I think it will be much easier to understand and improve your design and find appropriate solution.

Another advice is use data-driven way to operate with renderers. This way is about operating data items of data provider but not getting and setting data from outer document directly. Use data binding to bind changed data between different item renderers in different columns.


In this case, you might want to keep a boolean var isAddEnabled in your outerDocument and change your enabled as below:

enabled="{outerDocument.isAddEnabled}"

Change this isAddEnabled based on your validation criteria. As you don't want it to be applied to all your items, either keep a property in your dataProvider(preferred) OR maintain another collection of same length as your dataProvider (not recommended).

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜