tags:

views:

45

answers:

2

I have a datagrid which has id="myGrid" in my application, from it I call a component. Now from the 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?

A: 
  1. create a new MXML component and put all your DataGrid code inside
  2. user the new component instead of the datagrid and assign different ids
Adrian Pirvulescu
Given his description; I'd recommend extending the DataGrid to add a new property; not creating a new component that contains the DataGrid.
www.Flextras.com
why not using a new control? depends on the situation!
Adrian Pirvulescu
That said, the Original Poster is using a DataGrid. If he using composition to put the DataGrid inside a container, he will need to expose all the DataGrid properties that he is using as part of that new component and pass them through to the DataGrid. This is unneeded overhead. Additionally it adds an unnecessary container to his application which can have an affect performance and memory usage. I agree the chose depends on the situation, based on what we know from the original post; there is no benefit to enclosing the DataGrid in a container, but there are drawbacks.
www.Flextras.com
BTW, why did you downvote my answer twice? If you think it is faulty, please add a comment as to why.
www.Flextras.com
A: 

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?

www.Flextras.com
So, why was this downvoted?
www.Flextras.com