X2O lets you build database-driven Adobe® Flex®, Flash® and JavaScript apps
without any server-side development. This is the blog.
Thursday, February 5, 2009
Framework battles for the Flash platform:
Zend AMF vs. X2O
by Ka Wai Cheung
The Zend framework has been buzzing a lot in the Flex community recently. We're glad there are others trying to better integrate Flex development with a database server. Lee Brimelow created a nice video showing how to start a Flex app on top of Zend AMF. I'd like to compare the process with a similar setup in X2O.

Setting up a super-simple database-driven Flash/Flex application using Zend AMF
:
(A transcription of Lee Brimelow's tutorial)

  1. Download Zend AMF (currently version 1.7.4)
  2. Start up MAMP or WAMP to run your PHP web server locally
  3. Create a database in MySQL (In Lee's example, it's one flat table called Tutorials)
    1. Create a table called Tutorials (not shown in his example)
    2. Create fields in Tutorials (not shown in his example)
    3. Fill the database with a bunch of records (not shown in his example)
  4. Create a bootstrap file in PHP (the destination for your Flex service calls)
    1. Set up error-reporting
    2. Set up include paths to Zend framework folder
    3. Tell Zend server which PHP classes to use for remoting
    4. Test to make sure it's connecting
  5. Create a custom PHP class (In this case, Tutorials.php)
    1. Create connection to MySQL database
    2. Create a getTutorials()method that returns an array of data
      1. Create a MySQL query call to load data ("SELECT * From Tutorials")
      2. Create an array to push the resultant data
      3. Test that the PHP service class is mapping to the bootstrap file from the browser
  6. Open up Flex or Flash (Lee uses Flash CS3 in his example)
    1. Create a NetConnection and connect to your bootstrap file
    2. Create a Responder object, passing in an OnResult handler
    3. Call the PHP getTutorials() method, using NetConnection and Responder.
    4. Test that the call is connecting correctly to the PHP server*
    5. In the OnResult handler, write a for loop and iterate through the loosely-typed result object to trace out data.

* - It's worth noting, that in Lee's video, he misspelled the word "Tutorials" in his SQL query. A completely acceptable, routine mistake we all make while developing. He had to debug that error by trickling back into his PHP code to see what was wrong.
Setting up the same super-simple database-driven Flex application in X2O:

  1. Login to your X2O web client
  2. Create a new project
    1. Create an entity called Tutorials
    2. Create attributes within Tutorials
  3. Generate your project
  4. Download the resulting SWC file
  5. Go to the generated CMS and enter in dummy data for Tutorials
  6. Open up Flex or Flash CS4 (In our case, Flash CS3 is unsupported)
    1. Write a login command to securely connect to the X2O server
    2. Create an instance of the generated TutorialsCollectionVO, and call loadAll().
    3. Create an event handler for the X2O LoadComplete event
    4. Iterate through the strongly-typed TutorialsCollectionVO and trace out data.

Let's review.

How many steps?
There's roughly 18 individual tasks Lee did in Zend, compared to 10 in X2O (I'm not counting any "parent steps" as that's really just a composition of the child steps). But, that doesn't even begin to tell the story.

What are the prerequisites for Zend AMF v. X2O?
With the Zend framework, you'll need to know your way around MySQL, PHP development, MAMP (or WAMP) before you even get to Flash. With X2O, you don't need to know any other programming language or have any other environment setup.

Configuration and setup?
With Zend, you still need to configure a bunch of stuff. Point to the right database, connect to the right port. With X2O, there's no administrative work. And, it's hosted remotely, so everything's already online.

How much testing is there to do between Zend AMF and X2O?
There's no in-development unit-testing that has to be done with X2O. We don't have to check that our connection configurations are set properly, or that Flash is communicating with the server properly. The infrastructure is properly generated in step 3. With Zend, we have to spot check at various points (Is the database connecting properly? Is the bootstrap file running properly? Is the Flash NetConnection object connecting to the server properly?)

What else did X2O give us in those 9 steps?
What we just did in X2O also created a slew of other things that weren't created in Lee's Zend example:
  1. A secure, web-based CMS that lets anyone view, add, edit, or delete data
  2. AS3 Documentation to the generated SWC API
  3. We've also created a TutorialVO object that represents each tutorial record. You can use it to insert, update, or delete a new tutorial record straight from your Flash environment.
  4. All our generated objects are strongly-typed. Meaning, you get the added benefit of code-hinting on most IDEs.
  5. Standard methods to send emails and upload files through the X2O server.

How does the work scale when there's more stuff to add?
Suppose we wanted to add additional methods to the Zend version. Adding a simple InsertTutorial() method requires more PHP code, data validation, and more testing. If we wanted to add a new related table, there's database modeling and foreign key constraints. More data we have to add by hand in the database. More PHP code, more validation, more testing. As we move on in the development process, it gets a harder to find bugs when we're coding by hand.

With X2O, we add a new entity, create the attributes, relate them as need be, and regenerate. The old data remains intact, and we can go to our updated CMS to add in the new data. Because the entire backend infrastructure is generated, there's no need to worry that we made stupid human mistakes.

Talk is talk. We'll walk the walk.
Lee created a great tutorial. But, we'd like to show you how to do the same thing in a future X2O video as well, and post it right here. For now, here's our overview video:



7 Comments:

Blogger Stefan said...

First of all, I like the concept of your new service. But I'm afraid you compare apples and oranges. You assume that your service is equally useful to all kinds of clients. I guess that most clients want to store their data on their own server. For these clients your service is totally inappropriate, they don't care how many steps a developer may need to do his job.


Blogger Mustafa Shabib said...

Hey Stefan --

I agree that the way X2O's beta release is currently set up, it doesn't offer nearly any of the control that comes with hosting your own data. However, we have plans in the future to release a more robust version of X2O that can be hosted on your own servers that we can work together with companies to set up. That way, people can get the control and security of hosting their own data as well as the simplified data-modeling and Flex integration benefits of X2O.


Blogger fede said...

I don't understand, or maybe I missed something. You are comparing an open source platform with your application? It's a proprietary closed source software, right? I can see Adobe doing something like this, and maybe they do, but today big companies are focusing not only in open source technologies, but also in open source communities. Google, IBM (CouchDB), Sun, Microsoft and Adobe are great examples of this.


Blogger kawai17 said...

@Fede-

The comparison here is not so much about open source v. closed source, but in the philosophical approach to developing Flex apps.

Here, I'm trying to show the unique capabilities of X2O - remotely hosted database, no server-side development, completely focused on the Flex/AS3 end.

@Stefan-

I agree, there may be a bit of apples to oranges comparison here at the lower level. But higher-level, we're comparing two ways of pulling and working with data from a database to Flex. They are very different approaches and we think ours has some unique advantages.


Blogger Pickle said...

Really cool idea. Giving your users a "free" CMS will be a huge incentive to use this solution over Zend. However, in your demo video it looks like the CMS is HTML-Based. A CMS targeting flash should be Flash-Based! NOT HTML-Based. Ideally, you would actually have both types, with the HTML version designed specifically for smart phones, ipod touch, etc.


Blogger kawai17 said...

@Pickle-

You're right...the CMS is written in HTML. I don't necessarily agree however, that, just because we are offering a Flash-specific generating framework means we have to build our supporting tools in Flash.

In fact, I think something like a CMS is probably better executed in HTML (in general) which is why we went that route.

However, I agree - it would be a nifty exercise to take the generated SWC file and then create your own Flex CMS using the objects and methods available.

Also, do note that X2O now also generates a corresponding JavaScript library - so we're hoping to take the X2O philosophy over to other technologies.


Blogger Pickle said...

Sorry didn't realize HTML vs Flash CMS would be such a point of contention. I just think users prefer CMS's to be WYSIWYG. Since flash renders HTML quite differently than web browsers do, an HTML CMS forces you to constantly reload the page to check your updates. In contrast, a Flash CMS is pixel-perfect.


Post a Comment

<< Home

New to X2O?
Here's how to get started...
Subscribe to our RSS feed


Recent Posts
Previous Months
Also from the makers of X2O