Working with Persistent Data
I frequently hear the question, “How do I save data?” This question often gets asked with regards to the ContactManager application, such as “How do I make the save button work?” “Shouldn’t data binding do that?”
I talk about this in the book, and it’s an understandable misconception. There’s no easy answer. Saving data sounds simple enough–but where are you saving it? To the hard drive? To a database? To a text file? What kind of server, etc? How do you deal with authenticating who can save the data? What if two people try to save different data at once? All these questions must be answered.
Some of this is addressed in the final chapter. But the short answer is you need specialized skills to work with saving data, especially remotely, and this is outside the scope of this book. If you’d like to work with local data, check out AIR, or look at the new APIs in Flash 10 that let you access the local hard drive.
4 comments4 Comments so far
Leave a reply

I’m interested in a more limited goal, saving the changes made in a form back to the data model. Referencing your ContactManager example from Chapger 12, I’m interested in how to get the changes made in the “Contact Editor” view back to contactsDataGrid.selectedItem. I was hoping the data binding in the TextInput and other form items would take care of that automatically.
Yeah, bindings aren’t bidirectional in Flex 3. The easiest way would be to manually go through them. You could also look at using a model. You’d do something like bind the DataGrid to an or tag. In turn, you’d bind the model’s nodes to individual form elements, so that data comes in from the form, populates the model, which in turn populates the DataGrid. That might get you what you wanted. See page 83 of the book for more info on using data models. However, your case I would recommend just using ActionScript to manually move the data. It would probably be easier in the long run. Flex 4 may have new binding abilities to make this scenario easier.
First off, great job on the book, Aleric (this coming from a fellow Anthropology major!). Seriously, it makes Flex seem relatively easy.
As for the data binding questions, just a couple of thoughts. First, you can always “Create an application from Database” under the DATA menu. This provides some valuable script which you can emulate in your own project to edit and save to a DB.
Also, Lee Brimlow offers some excellent (and free) tutorials for both Flash and Flex at gotoandlearn.com – he has a great tutorial there on AMFPHP remoting. Also, he has an outstanding video on the Adobe free “Flex in 5 days” site. And finally, the Flex tutorials on Lynda.com also cover this topic in depth.
Best of luck to all and hope that helps.
Chris
I would like to make a comment, possibly obvious to many, that the save issue is really a question about what things you can/should do on the client side versus the server side. Saving is a server side issue, so it isn’t really in the domain of Flex, except for communicating with the server. This underlies all that Mr. Cole says at the top of this page, but it may not be obvious to everyone that this is the issue. At least, this wasn’t specifically stated anywhere that I saw.
Gary