Legal
The views expressed in this blog are my own and do not necessarily reflect the views of Adobe Systems Incorporated.
Search
July 25, 2006
Ajax, JSON, PHP, and Flex together to build a Flash-y Ajax site
In honor of the O'Reilly Open Source conference that I and other Adobe people at attending, I'm happy to show an example of building out a site that combines Ajax, JSON, PHP, and Flex into one application, with 90% of this being done with open source software (the only piece that is not open source, but is free (in terms of cost), is the Flex SDK). I've created a site that tries to mimics the experience of Google Finance, a great site that combines Ajax, and Flash together to provide a great user experience.
This tutorial, available online in PDF format with complete source code in this .zip file, shows how to take data from your Feedburner feed, and create an Ajax application that displays the dates and hits of your feed. It will then take that information and populate a graph that we've created with Flex and the Adobe Flex Charting components, using the Flex / Ajax bridge from Ely Greenfield and the JSON ActionScript library from Mike Chambers, Christian Cantrell, Daniel Dura, and Darron Schall.
A working example of this is available on our wickeddemo.com website. (Note that because of load, that example will load data from a static XML file, rather than PHP.)
If you have any questions about this example, please post there here in this blog.
Here is what I've learned in using the Spry Ajax framework and Flex together:
I found it easiest to modify the HTML that gets output by Flex Builder, rather than to reference the built swf file in my own HTML file that I create. If you do that, be sure to modify index.template.html in the html-template/ folder of your Flex project, rather than the .html files in the bin/ directory of your Flex project. The HTML files in bin/ get overwritten when you save and re-build your Flex application, and if you modify those, rather than index.template.html, you'll lose your changes to index.template.html.
I started building out the Flex graph using JavaScript and the Flex / Ajax bridge. I don't recommend that. Build out your entire Flex component in Flex Builder, then simply write functions to pass data to it from HTML. I think that's easier than trying to build Flex components using JavaScript.
Similarly, write functions that closely couple your Flex application to your HTML page. For instance, you'll notice that in my MXML file, I call the chartClicked JS function using:
if( ExternalInterface.available )
ExternalInterface.call("chartClicked",clickEvent.hitData.item);I could have attached an observer to the lineChart instead, using the Flex / Ajax bridge, but I find it easier to get the data items and debug the application in Flex Builder, rather than trying to do that in JavaScript on the HTML page.
The ActionScript 3 JSON library doesn't like new lines or carriage returns in the JSON data. You need to strip those out before sending data from JS to ActionScript over the Flex / Ajax bridge.
- I don't know of any other technologies that I could use in this tutorial to get a higher click through on MXNA. Well, maybe Web 2.0. :)
technorati tags:flex, ajax, php, web2.0, json, adobe, flash
Blogged with Flock
Comments
This might be pretty cool, if I could see it. Unfortunately, the good people at Adobe have decided that we sysadmins on FreeBSD will never see Flash stuff. There being no Flash plugin for FreeBSD at all.
error in loadin flash download in test site. Error in right panel:
Observer Callback: onPreLoad
obs.onPostLoad called!
Observer Callback: onPostLoad
Error in onDataChanged[object Error]
[{"@date":"2006-07-01", "@circulation":"0", "@hits":"0", "ds_RowID":0}, {"@date":"2006-07-02", "@circulation":"0", "@hits":"0", "ds_RowID":1}, {"@date":"2006-07-03", "@circulation":"0", "@hits":"0", "ds_RowID":2}, {"@date":"2006-07-04", "@circulation":"0", "@hits":"0", "ds_RowID":3}, {"@date":"2006-07-05", "@circulation":"7", "@hits":"12", "ds_RowID":4}, {"@date":"2006-07-06", "@circulation":"17", "@hits":"57", "ds_RowID":5}, {"@date":"2006-07-07", "@circulation":"14", "@hits":"102", "ds_RowID":6}, {"@date":"2006-07-08", "@circulation":"9", "@hits":"26", "ds_RowID":7}, {"@date":"2006-07-09", "@circulation":"7", "@hits":"17", "ds_RowID":8}, {"@date":"2006-07-10", "@circulation":"15", "@hits":"56", "ds_RowID":9}, {"@date":"2006-07-11", "@circulation":"12", "@hits":"145", "ds_RowID":10}, {"@date":"2006-07-12", "@circulation":"20", "@hits":"185", "ds_RowID":11}, {"@date":"2006-07-13", "@circulation":"23", "@hits":"221", "ds_RowID":12}, {"@date":"2006-07-14", "@circulation":"26", "@hits":"214", "ds_RowID":13}, {"@date":"2006-07-15", "@circulation":"15", "@hits":"113", "ds_RowID":14}, {"@date":"2006-07-16", "@circulation":"13", "@hits":"97", "ds_RowID":15}, {"@date":"2006-07-17", "@circulation":"30", "@hits":"288", "ds_RowID":16}, {"@date":"2006-07-18", "@circulation":"34", "@hits":"310", "ds_RowID":17}, {"@date":"2006-07-19", "@circulation":"19", "@hits":"187", "ds_RowID":18}, {"@date":"2006-07-20", "@circulation":"33", "@hits":"432", "ds_RowID":19}, {"@date":"2006-07-21", "@circulation":"35", "@hits":"437", "ds_RowID":20}, {"@date":"2006-07-22", "@circulation":"20", "@hits":"130", "ds_RowID":21}, {"@date":"2006-07-23", "@circulation":"17", "@hits":"149", "ds_RowID":22}, {"@date":"2006-07-24", "@circulation":"29", "@hits":"337", "ds_RowID":23}]
Observer Callback: onDataChanged
The use of Flash pretty well quashes any speed gained by ajax/json, etc.
Thank you for signing in, You may now comment. (Sign Out)
(If you haven't left a comment here before, you may need to be approved by the site owner before your comment will appear. Until then, it won't appear on the entry. Thanks for waiting.)