Flextrine 0.7 released – now with ZendAMF!

After much soul searching I eventually decided to put in the time to convert Flextrine from using AMFPHP to ZendAMF.  There were a few reasons I decided to make this move, but eventually it boiled down to the fact that quite a few people had asked me to do so.  In retrospect it was certainly the right thing to do – ZendAMF has the green light from Adobe, its licence is LGPL instead of GPL and the cleaner code base means that the changes Flextrine requires can be implemented as overridden classes instead of having to modify the ZendAMF core.  This particularly is great news because it means that you can use Flextrine directly with the standard Zend framework installation, whereas previously you could only use the version of AMFPHP bundled with Flextrine.

Functionally speaking things remain exactly the same, and we continue to approach our stable release alongside Doctrine 2.

The new version of Flextrine can be downloaded from www.flextrine.com.  Note that if you are upgrading from a previous version of Flextrine you will need to regenerate your AS3 entities.

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

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

UPDATED FOR FLEXTRINE 0.6.5!

After numerous requests I have finally sat myself down to write a basic tutorial for using Flextrine in a practical and simple Flex application.

What is Flextrine?

In a sentence, Flextrine is an open-source solution for reading and writing AS3 objects to and from a remote database.  Flextrine doesn’t really do anything that you couldn’t do by hand using PHP and AS3 code, but it removes most of the grunt work and standardises client-server database interactions.  All being well, database aware Flex applications coded using Flextrine are shorter, more readable and more maintainable.

Documentation for Flextrine is available in its Google Code wiki and its definitely worth having a skim through before beginning the tutorial.

What shall we build?

In this tutorial we are going to demonstrate some of Flextrine’s functionality by building a simple online contacts manager.  The application will allow us to create, edit and delete contacts, each of which simply have names and telephone numbers.  In order to demonstrate some of Flextrine’s associations we will also allow the user to put contacts into groups.

Note that the purpose of this tutorial is to demonstrate Flextrine rather than Flex, so we won’t be using any frameworks (apart from Flex itself) and where there is a choice between an elegant programming solution and just keeping it simple we’ll be going for the simpler option 🙂

Requirements

To run through this tutorial you will need the following:

  • Flex SDK 4 (free from Adobe)
  • A nice Flex IDE – I personally use the wonderful FlashDevelop, but Flash Builder 4 will do just as well
  • A web server running PHP 5.3+ and MySQL (WAMP for Windows and MAMP for OSX are good choices)
  • Download the complete source code for the tutorial and save yourself tedious typing!  This does not include the Flextrine AS3 code so you will need to add the source code or SWC to your classpath manually before compiling.

Lets begin by installing Flextrine and its dependencies.

Using Catalyst with FlashDevelop

Adobe have just released the first version of Catalyst, a great addition to the Adobe suite which addresses the long-standing annoyances of skinning Flex applications.  Basically Catalyst allows you to take a PSD or AI file, chop it up into Flex components, optionally add some interactions and then export the whole shebang info Flash Builder 4 so you can start coding.  However, Catalyst only wants to save a Flash Builder readable FXP file which is no use for the likes of us who use FlashDevelop.  Luckily it turns out that FXP files are just normal zips of the Flash Builder code tree, so we can extract the assets into a FlashDevelop project using a simple script.  Note that you will need to download unzip.exe and put it into your path for this to work.

First of all create a folder called ‘fxp’ in the root level of your FlashDevelop project.  Then save your Catalyst project to this project (you can call it anything as long as it has an fxp extension).  Then create a text file, also in the root of your project called ExtractCatalystProject.bat and put the following code into it:

   1: unzip.exe fxp/*.fxp -x html-template/* .* libs/* src/PrivateData.mxml mimetype

Now to import the Catalyst project into your application right click on the bat file and choose ‘Execute’.  Every time you make a graphical change in Catalyst run the script again to extract.  Obviously you’ll have to be careful not to make any changes to the generated code in FlashDevelop otherwise it will get overwritten next time you extract.

Obviously this is a very simple solution and there are certainly better ways to do this (C# script macro anyone?), but as a first solution this seems to work ok 🙂