Accessing Flex’s objects by id
I have a datagrid which has id="myGrid"
in my application, from it I call a component. Now from t开发者_运维技巧he component I can call parentDocument.myGrid.selectedIndex = 0;
and it works fine.
But I want to make the component reusable, and I would like to pass the ID to the component each time, so myGrid
will change, how to properly send the ID to the component, and use it in the component?
I would extend the DataGrid to add the new property that you can pass in. When creating a new component, there is an option to "extend" an existing component; so just extend the DataGrid. This will give you all the properties of the DataGrid. The property can be something like this:
public var myParentDoc : UICpomponent;
However, since you didn't explain what you're doing, I'm not sure I completely understand how you're using parentDocument or for what purpose. Where in your DataGrid are you using parentDocument? In an eventListener? Or in an itemRenderer?
- create a new MXML component and put all your DataGrid code inside
- user the new component instead of the datagrid and assign different ids
精彩评论