views:

24

answers:

1

I have a form that is written in MXML that allows a user to create/add a User.

I need to add a form that allows a user to modify SOME but NOT ALL of the fields for this user.

The forms are so similar, I don't want to have to create two separate forms, one for Add and one for Modify.

For example, in the Add form, the user specifies a user id. In the Modify form, the "user id" field is not editable.

I'm wondering how I can initialize the MXML form (i.e. pass in a parameter?) so that it knows whether it is in the Add state or the Modif state.

I know I can't do the following but this is what I would like to do (pseudocode):

if (ADD_FORM) {
mx:TextInput id="txtUserID"
}
else {
mx:Label id="lblUserID"
}

+1  A: 

This kind of thing is handled well with states. In Flex 3 you define your states like view, add, and edit. Then you can add the components that are common to all states to the document. Within each state declaration, you can then add the components that are specific to only some states. You can have the edit state dependent on add state since edit is add plus a few more fields.

In Flex 4 this is even easier. You declare your states, and then inline in the single document have all content for all states, with includeIn attributes for which states each element should be included in (or excludeIn).

Sam
Thanks so much for your suggestion Sam. The view states was absolutely the answer and it worked quite well.Thanks for the info about Flex 4. That sounds pretty cool and I'll definitely look into that feature.
fortpointuiguy