« Flextrine Tutorial – CRUD in a simple Flex 4 address book: Creating new entities
» Flextrine Tutorial – CRUD in a simple Flex 4 address book: Updating entities

Actionscript 3.0, FlashDevelop, Flex 4, PHP

Flextrine Tutorial – CRUD in a simple Flex 4 address book: Deleting entities

08.03.10 | Comment?

Introduction
Setting up the server
Creating the entities
Creating the database schema
Loading the entities
Creating new entities
Deleting entities
Updating entities
Conclusion

Deleting entities is very simple.  Update the delete button MXML tag to call onDeleteClick() when clicked, and to only be enabled if there is a selection in the tree.

   1: <s:Button label="Delete" click="onDeleteClick()" enabled="{tree.selectedItem != null}" />

And implement the onDeleteClick() method:

   1: private function onDeleteClick():void {

   2:     em.remove(tree.selectedItem);

   3:     

   4:     if (tree.selectedItem is Contact)

   5:         tree.selectedItem.contactGroup.removeContact(tree.selectedItem);

   6:     

   7: }

Notice that we maintain the bi-directional association if the deleted item is a contact by removing it from its associated contactGroup.

And that’s it :)  The entity will be removed from its entity repository (updating the tree via databinding) and on the next flush() it will be removed from the database.

The final step in our little address book is to allow the user to update existing entities.

Social bookmarks:
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google

have your say

Add your comment below, or trackback from your own site. Subscribe to these comments.

Be nice. Keep it clean. Stay on topic. No spam.

You can use these tags:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

:

:


« Flextrine Tutorial – CRUD in a simple Flex 4 address book: Creating new entities
» Flextrine Tutorial – CRUD in a simple Flex 4 address book: Updating entities