views:

37

answers:

1

I have something like 10 components that have code that's very similar, except for the target that it's applied to and some other minor differences.

For example, I return xml to component1 and component2 that differs in this way:

component 1: event.result.names.name
component 2: event.result.phones.phone

I then bind these to a List, and the name of that list differs by component.

component 1: nameslist.dataProvider = 
component 2: phoneslist.dataProvider = 

How do I create a single method that would accept as parameters just the names/pointers/references to the objects I need worked on. For examples nameslist or phoneslist as List or .phones.phone vs. .names.name for the structure of the xml returned?

+2  A: 

It sounds to me like you can use a function as parameters to your component.

So, you'll have a property like this:

public var dataProviderFunction : Function;

and the value you'd give it might be something like this:

public function getNamesDataProvider(object:XML):xml{ return xml.namesList.dataProvider }

Or like this:

public function getNamesDataProvider(object:XML):xml{ return xml.phonesList.dataProvider }

Take a look at how the List class source code and see how the labelFunction and itemToLabel are implemented.

www.Flextras.com
Hi Jeffry, Thanks for the answer. Is this code supposed to be in the main application file? Sorry, I'm still a little confused. Haven't wrapped my head totally around your answer.
duder
The public var would go in your component. The function that you're using as an argument would most likely go in the component's parent. If you provided a full sample, it would be easier to point and say "put it here".
www.Flextras.com