views:

38

answers:

2

I have a custom component based on mx:ComboBox. Within it I connect to an HTTPService (the url is passed as a paramter) and bind the combobox. Parameters to be sent to the HTTPService are passed to the component. This is working fine. But I want to modify it to make it re-usable with other HTTP service URLs, which return the XML in a different format.

My challenge is how can I bind a custom component to a node dynamically at runtime?

The MXML code of the component looks like this:

<mx:ComboBox xmlns:mx="http://www.adobe.com/2006/mxml" 
  dataProvider="{myData.person}
    <mx:HTTPService id="serviceTest"
        resultFormat="e4x" 
        result="myResultHandler(event);" 
        fault="myFaultHandler(event);" />
</mx:ComboBox>

I may need to change

myData.person

to:

myData.region

Can this be done in MXML?

Or can it be done in Actionscript? Is there something like:

this.dataProvider = myData.[person];

The trick is I will not know what to bind to, as the XML will be different each time it is used.

Is this possible? Or any workaround that achieves the same thing?

EDIT: It works with the "child" property.

dataProvider="{myData.child(myDataField)}"

But that doesn't work if the data field is further nested. E.g. myData.people.person

Is there a way to get it to work if the data field is nested under another node? Can this be done using an XPATH expression or something else?

A: 

Use the "child" property.

HappyCoder4U
Nope, this doesn't work if the node is further nested. E.g. myData.people.person
HappyCoder4U
A: 

Its not possible. 'Bind' is (Flex) framework ability - not standard (AS) language construction. You have to manage all events itself.

DoubleThink
HappyCoder4U