0

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?

2 Answers 2

1

Use the "child" property.

Sign up to request clarification or add additional context in comments.

1 Comment

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

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

1 Comment

Either I'm not understanding you or you're not understanding me. I am handling the result & fault events of the HTTPservice. I am able to get the component to work - I just cannot make it a generic component. Which events are you speaking of? Could you please explain a bit?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.