|
|
SYS-CON MAGAZINES |
TOP LINUX LINKS YOU MUST CLICK ON AJAXWorld News Desk
AJAX, JSON, PHP, and Flex Together
Google has done a great job at using Flash where it makes the most sense, in the graphs for company quotes
By: Mike Potter
Sep. 30, 2006 10:15 AM
Digg This!
Page 1 of 2
next page »
We've all seen Google finance, and the great job that it does at mixing HTML content with Flash content, as seen on company stock quotes. Google has done a great job at using Flash where it makes the most sense, in the graphs for company quotes, with HTML where it makes sense (linking to news items). Today, I'll show you how to build your own Google-finance type site, using a combination of Ajax, JSON, PHP and Flex / Flash. And, best of all, we'll do it all for free.
To complete this tutorial, you'll need the following software / accounts: The first part to this tutorial is to install all the above software. I won't go through that here, if you have problems please comment in my blog. Believe it or not, there actually are pieces of Adobe software that I don't use, feel free to use Photoshop to design the appearance of the webpage, Lightroom to hold photos of pepople you will put on the HTML page, Premiere to do video editing, ColdFusion can replace the PHP part fairly easily etc... I leave it up to you to extend this tutorial to make use of every piece of Adobe software. Once we've got everything installed, we'll start by hooking up our PHP backend to Spry. The reason that we need the PHP backend is because Ajax applications cannot load data from outside sources: we need to load data from the same source as the Ajax application. So, we've created a small PHP file that will go to Feedburner, get the stats and then print the output. That PHP file is very small and very simple:
<?php Any server side language could do something similar. And here's the JavaScript code for Spry to call and load that PHP file: var dsFeedburner = new Spry.Data.XMLDataSet("getdata.php", "/rsp/feed/entry"); When the HTML page loads, it will call getdata.php, and populate the Spry dsFeedburner data source with data from that file. Here's a sample of the XML content that gets output from that PHP file.
<?xml version="1.0" encoding="UTF-8"?> The text "/rsp/feed/entry" is simply an xpath expression to get to each <entry... item in the XML file. So, now we've got the data. To populate a table with data, we do the following:
<table border="1" spry:region="dsFeedburner"> We repeat each table row (<tr>) with the spry:repeat="dsFeedburner" attribute. We set the selected item's CSS class to "SelectedFeedburnerItem", and the hover state to "HoverFeedburnerItem". You can edit the style for those items with simple CSS, in the HTML file (or an external CSS file, whichever you prefer.) OK, so if we run that, then we should see a repeatable table showing dates and hits to our items. Pretty good, now let's hook that up to a graph component that we made in Flex. Its important to note here that Flex can be used to create a number of components. Its possible, with a little work, that you could create a component that exactly matches the graphing component that Google uses, with a date slider / selector at the top, above the graph. I won't do that here, for the sake of simplicity, but it is possible. Or, you could create an Ajax media browser that plays videos in Flash. The possibilities are limited only by your imagination. So, let's go ahead and create our Flex graph... Here's the MXML code:
<?xml version="1.0" encoding="utf-8"?> Everything should be fairly self-explanatory. The only lines that may be unfamiliar are:
<fab:FABridge xmlns:fab="bridge.*" /> There's lots going on here. First, we create an observer on the data's "onDataChanged" method, so every time the data is changed, we send new data to the Flex application. Although we only use this once, when the page is loaded, you could use this if you had say a drop down list of a number of your feeds, and wanted the data source to change when the drop down changed. When you changed your Spry data source, the Flex graph would refresh because of this observer. Page 1 of 2 next page »
Subscribe to our RSS feeds now and receive the next article instantly!SUBSCRIBE TO THE WORLD'S MOST POWERFUL NEWSLETTERS |
|
|||||||||||