19 November 2008

Flex Data Models

One of the powerful features of Flex is the <mx:model> tag. You can bind fields and variables to it; when a user updates a value in a TextInput, if that field is bound to a model, the value in the model will be updated too. You can then pass the model object to your server-side technology. Recently, I needed to pass some search parameters to an HTTPService:

<mx:model id="serviceModel">

The above model object came in handy. It's basically an XML object with whatever structure you'd like to give it. Note the first two nodes off of <root> are bound to TextInput fields; the last is bound to a private variable. When the value of the variables change, so do their values in the model.

Then when I'm calling the HTTPService, I simply pass the model object to it:


No comments: