Using Wordpress as a backend for Flex or Flash
History Key
- New content
Removed content
Recent Versions
Choose two versions to compare, or click the link to view it.
Using Wordpress as a backend data source beta
Ok, I know what you're thinking. Why? Well, the main reason is it's easy for you or the customer to edit the content. It's also quick to setup. For small to mid-sized projects this means you can focus on client side work rather than reproducing the server side code again and again. It provides authentication out of the box. It provides categories and tags out of the box. It provides a way for your customers to upload media. It lets you create the front end in Flash, Flex or AJAX. It provides alternative HTML content if Flash is not available. It's SEO friendly. You get the data as XML so you can use E4X which is fun and easy to use. You can use it with my new Flex Capacitor Link Manager project and create full fledged deep linked sites in record time (the link manager is still in beta and not recommended for production environments).
So you can use Wordpress as a database. Think it through. You can create and publish posts (basically records) using Wordpress administration pages and then retrieve that data (in XML format) into Flex. Wordpress lets you create and set custom fields on any post so you can create things posts that contain additional fields like product, price, weight, etc. You will see this option on the Create and Edit posts page. You can get at this data extremely easily. Insanely easy beta. So let's take a look at an example site and how we do this...
The Example
This is a pretty straight forward crummy example. All it is doing is loading in the most recent posts from Wordpress and displaying them in our Flex application (we could have used Flash or AJAX to get the XML just as easily). The application is about 80kb with an RSL and 270kb without an RSL. Remember this is the same size or less than a HTML page with graphics. The larger size takes less than a second to load on a fast connection and a few seconds on a slow connection. Remember to get the content we simply use an HTTPService, point it to our site and append, "xml=1" to the query. That tells Wordpress to only send the data we are requesting and return that data in valid XML so you can navigate it using E4X.
Here's the XML it returns to Flex
<?xml version="1.0" encoding="iso-8859-1"?>
<wordpress>
<info name="wordpress" url="http://www.flexcapacitor.com/wordpress" time="Sunday, December 26th, 2010" siteurl="http://www.flexcapacitor.com/wordpress" description="A Wordpress Site" rdf_url="http://www.flexcapacitor.com/wordpress/?feed=rdf" rss_url="http://www.flexcapacitor.com/wordpress/?feed=rss" rss2_url="http://www.flexcapacitor.com/wordpress/?feed=rss2" atom_url="http://www.flexcapacitor.com/wordpress/?feed=atom" comments_atom_url="http://www.flexcapacitor.com/wordpress/?feed=comments-atom" comments_rss2_url="http://www.flexcapacitor.com/wordpress/?feed=comments-rss2" pingback_url="http://www.flexcapacitor.com/wordpress/xmlrpc.php" stylesheet_url="http://www.flexcapacitor.com/wordpress/wp-content/themes/twentyten/style.css" stylesheet_directory="http://www.flexcapacitor.com/wordpress/wp-content/themes/twentyten" template_directory="http://www.flexcapacitor.com/wordpress/wp-content/themes/twentyten" template_url="http://www.flexcapacitor.com/wordpress/wp-content/themes/twentyten" charset="UTF-8" html_type="text/html" version="3.0.4" language="en-US" text_direction="ltr"/>
<posts>
<post id="7" title="The Third Post" dateCreated="December 26th, 2010" date_created_iso="20101226T01:39:22Z" date_created_gmt="2010-12-26 01:39:22" permalink="http://www.flexcapacitor.com/wordpress/?p=7" permalinkXML="http://www.flexcapacitor.com/wordpress/?p=7&xml=1" author="admin" allowComments="1" allowPings="1" commentCount="0" commentStatus="open" description="" excerpt="" guid="http://www.flexcapacitor.com/wordpress/?p=7" link="" menuOrder="0" pinged="" postCategory="" postContentFiltered="" postID="7" postModified="2010-12-26 01:39:22" postModifiedGMT="2010-12-26 01:39:22" postParent="0" postStatus="publish" postType="post" postMIMEType="" slug="the-letter-c" textMore="" toPing="" userID="1">
<content><![CDATA[The third post]]></content>
<ancestors/>
<categories>
<category id="1" name="Uncategorized"/>
</categories>
<customFields>
<customField name="_edit_last"><![CDATA[1]]></customField>
<customField name="_edit_lock"><![CDATA[1293327563]]></customField>
<customField name="_wp_old_slug"><![CDATA[]]></customField>
<customField name="podPressPostSpecific"><![CDATA[a:6:{s:15:"itunes:subtitle";s:15:"##PostExcerpt##";s:14:"itunes:summary";s:15:"##PostExcerpt##";s:15:"itunes:keywords";s:17:"##WordPressCats##";s:13:"itunes:author";s:10:"##Global##";s:15:"itunes:explicit";s:7:"Default";s:12:"itunes:block";s:7:"Default";}]]></customField>
</customFields>
<tags/>
</post>
<post id="3" title="Second post" dateCreated="December 25th, 2010" date_created_iso="20101225T19:40:55Z" date_created_gmt="2010-12-25 19:40:55" permalink="http://www.flexcapacitor.com/wordpress/?p=3" permalinkXML="http://www.flexcapacitor.com/wordpress/?p=3&xml=1" author="admin" allowComments="1" allowPings="1" commentCount="0" commentStatus="open" description="" excerpt="" guid="http://www.flexcapacitor.com/wordpress/?p=3" link="" menuOrder="0" pinged="" postCategory="" postContentFiltered="" postID="3" postModified="2010-12-25 19:40:55" postModifiedGMT="2010-12-25 19:40:55" postParent="0" postStatus="publish" postType="post" postMIMEType="" slug="second-post" textMore="" toPing="" userID="1">
<content><![CDATA[second post]]></content>
<ancestors/>
<categories>
<category id="1" name="Uncategorized"/>
</categories>
<customFields>
<customField name="_edit_last"><![CDATA[1]]></customField>
<customField name="_wp_old_slug"><![CDATA[]]></customField>
<customField name="_edit_lock"><![CDATA[1293306055]]></customField>
</customFields>
<tags/>
</post>
<post id="1" title="The First Post" dateCreated="December 20th, 2010" date_created_iso="20101220T13:55:25Z" date_created_gmt="2010-12-20 13:55:25" permalink="http://www.flexcapacitor.com/wordpress/?p=1" permalinkXML="http://www.flexcapacitor.com/wordpress/?p=1&xml=1" author="admin" allowComments="1" allowPings="1" commentCount="1" commentStatus="open" description="" excerpt="" guid="http://www.flexcapacitor.com/wordpress/?p=1" link="" menuOrder="0" pinged="" postCategory="" postContentFiltered="" postID="1" postModified="2010-12-26 04:00:41" postModifiedGMT="2010-12-26 04:00:41" postParent="0" postStatus="publish" postType="post" postMIMEType="" slug="hello-world" textMore="" toPing="" userID="1">
<content><![CDATA[
The first post]]></content>
<ancestors/>
<categories>
<category id="1" name="Uncategorized"/>
</categories>
<customFields>
<customField name="_edit_lock"><![CDATA[1293336042]]></customField>
<customField name="_edit_last"><![CDATA[1]]></customField>
<customField name="podPressPostSpecific"><![CDATA[a:6:{s:15:"itunes:subtitle";s:15:"##PostExcerpt##";s:14:"itunes:summary";s:15:"##PostExcerpt##";s:15:"itunes:keywords";s:17:"##WordPressCats##";s:13:"itunes:author";s:10:"##Global##";s:15:"itunes:explicit";s:7:"Default";s:12:"itunes:block";s:7:"Default";}]]></customField>
</customFields>
<tags/>
<comments>
<comment id="1" postID="1" authorURL="http://wordpress.org/" author="Mr WordPress" dateCreated="December 20th, 2010" date="2010-12-20 13:55:25" dateGMT="2010-12-20 13:55:25" karma="0" approved="1" agent="" parent="0">
<content><![CDATA[Hi, this is a comment.<br />To delete a comment, just log in and view the post's comments. There you will have the option to edit or delete them.]]></content>
</comment>
</comments>
</post>
</posts>
<links>
<navigation>
<nextPosts></nextPosts>
</navigation>
<navigation>
<previousPosts></previousPosts>
</navigation>
</links>
<pages>
<page id="2" name="about" title="About" date="2010-12-20 13:55:25" category="" authorID="1" modified="2010-12-20 13:55:25"/>
</pages>
<archives>
<archive url="http://www.flexcapacitor.com/wordpress/?m=201012" search="m" value="201012" name="December 2010"/>
</archives>
<categories>
<category termID="1" name="Uncategorized" slug="uncategorized" termGroup="0" termTaxonomyID="1" taxonomy="category" description="" parent="0" count="3" categoryID="1"/>
</categories>
<bookmarks>
<bookmark id="1" url="http://codex.wordpress.org/" name="Documentation" image="" target="" category="" description="" visible="Y" owner="1" rating="0" updated="0000-00-00 00:00:00" rel="" notes="" rss="" recentlyUpdated=""/>
<bookmark id="5" url="http://wordpress.org/extend/plugins/" name="Plugins" image="" target="" category="" description="" visible="Y" owner="1" rating="0" updated="0000-00-00 00:00:00" rel="" notes="" rss="" recentlyUpdated=""/>
<bookmark id="3" url="http://wordpress.org/extend/ideas/" name="Suggest Ideas" image="" target="" category="" description="" visible="Y" owner="1" rating="0" updated="0000-00-00 00:00:00" rel="" notes="" rss="" recentlyUpdated=""/>
<bookmark id="4" url="http://wordpress.org/support/" name="Support Forum" image="" target="" category="" description="" visible="Y" owner="1" rating="0" updated="0000-00-00 00:00:00" rel="" notes="" rss="" recentlyUpdated=""/>
<bookmark id="6" url="http://wordpress.org/extend/themes/" name="Themes" image="" target="" category="" description="" visible="Y" owner="1" rating="0" updated="0000-00-00 00:00:00" rel="" notes="" rss="" recentlyUpdated=""/>
<bookmark id="2" url="http://wordpress.org/news/" name="WordPress Blog" image="" target="" category="" description="" visible="Y" owner="1" rating="0" updated="0000-00-00 00:00:00" rel="" notes="" rss="http://wordpress.org/news/feed/" recentlyUpdated=""/>
<bookmark id="7" url="http://planet.wordpress.org/" name="WordPress Planet" image="" target="" category="" description="" visible="Y" owner="1" rating="0" updated="0000-00-00 00:00:00" rel="" notes="" rss="" recentlyUpdated=""/>
</bookmarks>
</wordpress>
The Setup
First beta install Wordpress on your local or remote server. If you use a company like dreamhost they have pages, "goodies" that will automate this and install a Wordpress site in 10 minutes.
After you have Wordpress installed login and go to Appearance > Theme Editor.
Open the Header template (header.php).
At the very top of the page add this code:
header.phpbeta
<?php
# Copyright 2009 Flex Capacitor
# v 1.0.2
# http://www.assembla.com/wiki/show/flexcapacitor/Using_Wordpress_as_a_backend_for_Flex_or_Flash
$vars = get_defined_vars();
#print_r_tree($vars);
# Start XML output
if ($_POST['xml']==1 || $_GET['xml']==1) :
// We could set the content type to XML but I'm hesitant for a variety of reasons
// including choosing the correct character set, language support, testing purposes, etc
//header( "content-type: application/xml; charset=ISO-8859-15" );
$rootName = 'wordpress';
$nextPostLabel = 'Newer Entries »';
$previousPostLabel = '« Older Entries';
# specifies to return xml - the & is getting encoded to & ???
$xmlCall = '&xml=1';
# Create XML DOM Document
$dom = new DOMdocument('1.0', 'iso-8859-1');
# Generate nice output
$dom->formatOutput = true;
# Create root XML element
$root = $dom->appendChild($dom->createElement($rootName));
# Add blog info
$blogInfo = $root->appendChild($dom->createElement('info'));
$blogInfo->setAttribute('name', get_bloginfo('name', 'display'));
$blogInfo->setAttribute('url', get_bloginfo('url', 'display'));
$blogInfo->setAttribute('time', apply_filters('the_time', get_the_time( 'l, F jS, Y' ), 'l, F jS, Y'));
$blogInfo->setAttribute('siteurl', get_bloginfo('siteurl', 'display'));
$blogInfo->setAttribute('description', get_bloginfo('description', 'display'));
$blogInfo->setAttribute('rdf_url', get_bloginfo('rdf_url', 'display'));
$blogInfo->setAttribute('rss_url', get_bloginfo('rss_url', 'display'));
$blogInfo->setAttribute('rss2_url', get_bloginfo('rss2_url', 'display'));
$blogInfo->setAttribute('atom_url', get_bloginfo('atom_url', 'display'));
$blogInfo->setAttribute('comments_atom_url', get_bloginfo('comments_atom_url', 'display'));
$blogInfo->setAttribute('comments_rss2_url', get_bloginfo('comments_rss2_url', 'display'));
$blogInfo->setAttribute('pingback_url', get_bloginfo('pingback_url', 'display'));
$blogInfo->setAttribute('stylesheet_url', get_bloginfo('stylesheet_url', 'display'));
$blogInfo->setAttribute('stylesheet_directory', get_bloginfo('stylesheet_directory', 'display'));
$blogInfo->setAttribute('stylesheet_directory', get_bloginfo('stylesheet_directory', 'display'));
$blogInfo->setAttribute('template_directory', get_bloginfo('template_directory', 'display'));
$blogInfo->setAttribute('template_url', get_bloginfo('template_url', 'display'));
$blogInfo->setAttribute('charset', get_bloginfo('charset', 'display'));
$blogInfo->setAttribute('html_type', get_bloginfo('html_type', 'display'));
$blogInfo->setAttribute('version', get_bloginfo('version', 'display'));
$blogInfo->setAttribute('language', get_bloginfo('language', 'display'));
$blogInfo->setAttribute('text_direction', get_bloginfo('text_direction', 'display'));
# Add posts info
$rows = $root->appendChild($dom->createElement('posts'));
while (have_posts()) : the_post();
# Create first row
$row = $dom->createElement('post');
$rows->appendChild($row);
# Add post attributes
$row->setAttribute('id', $post->ID);
$row->setAttribute('title', stripslashes($post->post_title));
# Add date attributes
$post_date = mysql2date('Ymd\TH:i:s\Z', $post->post_date);
$row->setAttribute('dateCreated', apply_filters('the_time', get_the_time( 'F jS, Y' ), 'F jS, Y'));
$row->setAttribute('date_created_iso', $post_date);
$row->setAttribute('date_created_gmt', $post->post_date_gmt);
# Add post content inside CDATA tags
$content = $dom->createElement('content');
$contentCDATA = $dom->createCDATASection($post->post_content);
$content->appendChild($contentCDATA);
$row->appendChild($content);
# Permalink
$row->setAttribute("permalink", post_permalink($post->ID));
$row->setAttribute("permalinkXML", post_permalink($post->ID).$xmlCall);
# Get the post author info
$authorInfo = get_userdata($post->post_author);
$row->setAttribute("author", $authorInfo->nickname);
$allow_comments = ('open' == $post->comment_status) ? 1 : 0;
$allow_pings = ('open' == $post->ping_status) ? 1 : 0;
$row->setAttribute("allowComments", $allow_comments);
$row->setAttribute("allowPings", $allow_pings);
$row->setAttribute("commentCount", $post->comment_count);
$row->setAttribute("commentStatus", $post->comment_status);
$row->setAttribute("description", $post->main);
$row->setAttribute("excerpt", $post->post_excerpt);
$row->setAttribute("guid", $post->guid);
$row->setAttribute("link", $post->link);
$row->setAttribute("menuOrder", $post->menu_order);
$row->setAttribute("pinged", $post->pinged);
$row->setAttribute("postCategory", $post->post_category);
$row->setAttribute("postContentFiltered", $post->post_content_filtered);
$row->setAttribute("postID", $post->ID);
$row->setAttribute("postModified", $post->post_modified);
$row->setAttribute("postModifiedGMT", $post->post_modified_gmt);
$row->setAttribute("postParent", $post->post_parent);
$row->setAttribute("postStatus", $post->post_status);
$row->setAttribute("postType", $post->post_type);
$row->setAttribute("postMIMEType", $post->post_mime_type);
$row->setAttribute("slug", $post->post_name);
$row->setAttribute("textMore", $post->extended);
$row->setAttribute("toPing", $post->to_ping);
$row->setAttribute("userID", $post->post_author);
# Get Ancestors
$ancestorsArray = array();
$ancestors = $row->appendChild($dom->createElement('ancestors'));
# Loop through ancestors
foreach($ancestorsArray as $value) {
$ancestor = $ancestors->appendChild($dom->createElement('ancestor'));
$ancestor->setAttribute('name', $value);
if (!is_null($value)) {
$ancestor->setAttribute('value', $value);
}
}
# Get Categories
$categoriesArray = array();
$catids = wp_get_post_categories($post->ID);
$categories = $row->appendChild($dom->createElement('categories'));
# Loop through categories and add
foreach($catids as $catid) {
$category = $categories->appendChild($dom->createElement('category'));
$category->setAttribute('id', $catid);
$category->setAttribute('name', get_cat_name($catid));
}
# Get Custom Fields
$customFieldsArray = array();
$customFieldsArray = get_post_custom( $post->ID );
$customFields = $row->appendChild($dom->createElement('customFields'));
# Loop through customFields
foreach($customFieldsArray as $key => $value) {
$customField = $customFields->appendChild($dom->createElement('customField'));
$customField->setAttribute('name', $key);
if (is_array($value)) { # todo: fix this
$customField->appendChild($dom->createCDATASection(implode(',', $value)));
}
else {
$customField->appendChild($dom->createCDATASection($value));
}
}
# Add post tags - can't get this to work
# Update: Testing with new code submitted by Jordon B.
$tags = $row->appendChild($dom->createElement('tags'));
$tagsArray = get_the_tags();
# Loop through tag list
# Errors out - Invalid argument supplied for foreach()
if (is_array($tagsArray)) {
foreach($tagsArray as $value) {
$tag = $tags->appendChild($dom->createElement('tag'));
$tag->setAttribute('name', $value->name);
}
}
endwhile;
# Links
$links = $root->appendChild($dom->createElement('links'));
# Add next posts link
$navigation = $links->appendChild($dom->createElement('navigation'));
$nextPosts = $navigation->appendChild($dom->createElement('nextPosts'));
$nextPosts->appendChild($dom->createTextNode(get_next_posts_link($nextPostLabel)));
# Add previous posts link
$navigation = $links->appendChild($dom->createElement('navigation'));
$previousPosts = $navigation->appendChild($dom->createElement('previousPosts'));
$previousPosts->appendChild($dom->createTextNode(get_previous_posts_link($previousPostLabel)));
# Add pages tags
$pages = $root->appendChild($dom->createElement('pages'));
$pagesList = get_pages();
foreach($pagesList as $pageItem) {
$page = $pages->appendChild($dom->createElement('page'));
$page->setAttribute('id', $pageItem->ID);
$page->setAttribute('name', $pageItem->post_name);
$page->setAttribute('title', $pageItem->post_title);
$page->setAttribute('date', $pageItem->post_date);
$page->setAttribute('category', $pageItem->post_category);
$page->setAttribute('authorID', $pageItem->post_author);
$page->setAttribute('modified', $pageItem->post_modified);
}
# Add Archives
# getting lazy here because there is no get_archives method that returns a recordset
# using regexp but we could create a dom out of this and then change the names that way as well
$archives = $root->appendChild($dom->createElement('archives'));
$archivesList = wp_get_archives('type=monthly&echo=0&format=none');
$archivesList = preg_replace("/<a /", "<archive ", $archivesList);
$archivesList = preg_replace("/a>/", "archive>", $archivesList);
$archivesList = preg_replace("/href=/", "url=", $archivesList);
$archivesList = preg_replace("/title=/", "name=", $archivesList);
$archivesList = preg_replace("/(url=[']([^']*(\?((\w+)=(.*))))[']) /", "$1 search='$5' value='$6' ", $archivesList);
$archivesList = preg_replace("/<([^>]+)>(.*?)(<\/\w+>)/", "<$1 />", $archivesList);
$archivesList = preg_replace("/'/", "\"", $archivesList);
$childDocument = new DOMDocument('1.0', 'iso-8859-1');
$childDocument->preserveWhiteSpace = false;
if ($archivesList) {
$childDocument->loadXML("<archives>".$archivesList."</archives>");
$archivesNode = $dom->importNode($childDocument->documentElement, true);
$archives->parentNode->replaceChild($archivesNode, $archives);
}
# Get Categories
$categories = $root->appendChild($dom->createElement('categories'));
$categoriesList = get_categories();
foreach($categoriesList as $categoryItem) {
$category = $categories->appendChild($dom->createElement('category'));
$category->setAttribute('termID', $categoryItem->term_id);
$category->setAttribute('name', $categoryItem->name);
$category->setAttribute('slug', $categoryItem->slug);
$category->setAttribute('termGroup', $categoryItem->term_group);
$category->setAttribute('termTaxonomyID', $categoryItem->term_taxonomy_id);
$category->setAttribute('taxonomy', $categoryItem->taxonomy);
$category->setAttribute('description', $categoryItem->description);
$category->setAttribute('parent', $categoryItem->parent);
$category->setAttribute('count', $categoryItem->count);
$category->setAttribute('categoryID', $categoryItem->cat_ID);
}
# Get Comments
if (is_singular) {
$commentsArray = array();
$commentsArray = $wpdb->get_results( $wpdb->prepare("SELECT * FROM $wpdb->comments WHERE comment_approved=1 AND comment_post_ID = %d", $post->ID) );
$comments = $row->appendChild($dom->createElement('comments'));
# Loop through comments array
foreach($commentsArray as $commentItem) {
$comment = $comments->appendChild($dom->createElement('comment'));
$comment->setAttribute('id', $commentItem->comment_ID);
$comment->setAttribute('postID', $commentItem->comment_post_ID);
$comment->setAttribute('authorURL', $commentItem->comment_author_url);
$comment->setAttribute('author', $commentItem->comment_author);
#$comment->setAttribute('authorEmail', $commentItem->comment_author_email);
$comment->setAttribute('dateCreated', mysql2date('F jS, Y', $commentItem->comment_date));
$comment->setAttribute('date', $commentItem->comment_date);
$comment->setAttribute('dateGMT', $commentItem->comment_date_gmt);
$comment->setAttribute('karma', $commentItem->comment_karma);
$comment->setAttribute('approved', $commentItem->comment_approved);
$comment->setAttribute('agent', $commentItem->comment_agent);
$comment->setAttribute('parent', $commentItem->comment_parent);
#$comment->setAttribute('userID', $commentItem->user_id);
$content = $dom->createElement('content');
$contentCDATA = $dom->createCDATASection($commentItem->comment_content);
$content->appendChild($contentCDATA);
$comment->appendChild($content);
#foreach($commentItem as $key=>$value) {
#echo $key . "=".$value."<br/>";
#}
}
}
# Get Bookmarks
$bookmarks = $root->appendChild($dom->createElement('bookmarks'));
$bookmarksList = get_bookmarks();
foreach($bookmarksList as $bookmarkItem) {
$bookmark = $bookmarks->appendChild($dom->createElement('bookmark'));
$bookmark->setAttribute('id', $bookmarkItem->link_id);
$bookmark->setAttribute('url', $bookmarkItem->link_url);
$bookmark->setAttribute('name', $bookmarkItem->link_name);
$bookmark->setAttribute('image', $bookmarkItem->link_image);
$bookmark->setAttribute('target', $bookmarkItem->link_target);
$bookmark->setAttribute('category', $bookmarkItem->link_category);
$bookmark->setAttribute('description', $bookmarkItem->link_description);
$bookmark->setAttribute('visible', $bookmarkItem->link_visible);
$bookmark->setAttribute('owner', $bookmarkItem->link_owner);
$bookmark->setAttribute('rating', $bookmarkItem->link_rating);
$bookmark->setAttribute('updated', $bookmarkItem->link_updated);
$bookmark->setAttribute('rel', $bookmarkItem->link_rel);
$bookmark->setAttribute('notes', $bookmarkItem->link_notes);
$bookmark->setAttribute('rss', $bookmarkItem->link_rss);
$bookmark->setAttribute('recentlyUpdated', $bookmarkItem->recently_updated);
#foreach($bookmarkItem as $key=>$value) {
# echo $key . "=".$value."<br/>";
#}
}
# Output the XML
echo $dom->saveXML();
# Close the stream to prevent anymore output
exit();
endif;
# The template starts here
?>
Now, open up a browser tab, goto your main page and append, "xml=1" to the URL like so, "http://www.flexcapacitor.com/content/?xml=1" It should return a blank page. View the source...
As you can see an XML file of all the dynamic goodies of the page supplied to you. Well, if you are reading this today as in friday I haven't added all the dynamic information yet. I'm going to take a walk and get some exercise and maybe layout at the beach. Then I might get a cappacino and sip it annoyingly slow for about an hour while I people watch and check twitter on my douche bag iphone. After that I might finish adding the rest of the dynamic content and even add more to this tutorial on hooking it up with Flex. Seeing how no one reads these things it's safe to write my pin number here, "235GDEcho!*" :P
Update: It's now munday. I've updated the code above and even created the single post (single.php) page to return comments. Hurray!
Update: You no longer have to post the code on separate pages. Including it in the header.php file is all that you need.
Here is the code you'd use in Flash Builder (or Flex Builder). You will have to clean up the HTML content returned in the XML file to make it FTML compatible, FTML being Flash Text Markup Language or the tags and HTML the way Flash sees it.
Update: There is a class is in the library that does this for you. You don't have to use them. Just use standard Text components. Updated code below:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application
xmlns:mx="http://www.adobe.com/2006/mxml"
verticalScrollPolicy="auto"
layout="absolute"
color="#333333"
backgroundColor="#ffffff"
creationComplete="content1.send()"
xmlns:formatters="com.flexcapacitor.formatters.*"
xmlns:managers="com.flexcapacitor.managers.*"
backgroundGradientColors="[#ffffff, #ffffff]"
backgroundGradientAlphas="[1.0, .9]"
viewSourceURL="srcview/index.html"
xmlns:utils="com.flexcapacitor.utils.*"
themeColor="#CCCCCC" xmlns:controls="com.flexcapacitor.controls.*"
verticalLineScrollSize="25">
<mx:Script>
<![CDATA[
import mx.controls.Alert;
]]>
</mx:Script>
<mx:Style>
global {
font-size:11;
}
VScrollBar {
trackColors: #F5F5F5, #F5F5F5;
themeColor: #AAAAAA;
}
Alert {
backgroundColor: #bbbbbb;
borderColor: #bbbbbb;
color: #000000;
}
TextAutoSize {
linkColor:#185fc0;
}
</mx:Style>
<utils:CompilationDate id="date1" />
<mx:HTTPService
id="content1"
resultFormat="e4x"
url="http://www.flexcapacitor.com/content/"
result="trace(event.result)"
fault="title1.htmlText=String(event.fault.message)">
<mx:request>
<xml>1</xml>
</mx:request>
</mx:HTTPService>
<formatters:FormatterSequence id="htmlFormatter">
<formatters:HTMLFormatter />
</formatters:FormatterSequence>
<mx:Text id="title1" y="26" htmlText="{content1.lastResult.info.@name}" fontSize="19" fontWeight="bold" horizontalCenter="0"/>
<mx:VBox id="contentVBox0" verticalGap="0" y="110" width="80%" horizontalCenter="0">
<mx:Repeater id="postsRepeater" dataProvider="{content1.lastResult.posts.post}" width="100%" x="0" y="0">
<mx:VBox id="contentVBox3" width="100%" verticalGap="0">
<mx:Canvas id="canvas0" width="100%" >
<mx:Text id="textlink0" text="Post Title" height="26" styleName="postTitle"
toolTip="{postsRepeater.currentItem.@title}"
htmlText="{postsRepeater.currentItem.@title}" fontSize="19" fontWeight="bold"/>
<mx:Text id="textautosize0" y="25" selectable="true" styleName="postDateCreated"
text="Saturday, January 1, 2009"
htmlText="{postsRepeater.currentItem.@dateCreated}" fontWeight="bold" color="#666666"/>
<controls:TextAutoSize id="postDescription0" width="100%" y="52" styleName="postDescription" text="Description area"
htmlText="{htmlFormatter.format(postsRepeater.currentItem.content)}"
link="Alert.show(event.text,'Hyperlink')"/>
</mx:Canvas>
<mx:Spacer id="spacer0" height="35" />
</mx:VBox>
</mx:Repeater>
<mx:VBox width="100%" horizontalAlign="center">
<mx:Text y="10" text="Authored..." htmlText="© {date1.currentYear} Authored on {date1.monthName} {date1.dayNumber}, {date1.year} {date1.hour}:{date1.minute} {date1.ampm} v{date1.version}. All Rights Reserved." height="22" fontWeight="bold"/>
</mx:VBox>
</mx:VBox>
<managers:MouseWheelManager />
<mx:Text y="65" text="v1"
htmlText="v{date1.version}" horizontalCenter="0" fontSize="8" fontWeight="bold"/>
<mx:Text y="52" text="v1 5:00:00"
toolTip="Previously compiled {date1.previousCompileHour}:{date1.previousCompileMinute}{date1.previousCompileAmpm}

Compile time difference {date1.timeDifferenceFormatted}"
htmlText="Compiled {date1.hour}:{date1.minute}{date1.ampm}" horizontalCenter="0" fontSize="9" color="#999999" fontWeight="bold"/>
</mx:Application>
This will error out if you run it because of security sandbox issues. You can do two things. Upload it to your server and point it to your own wordpress install (with the custom theme modifications shown above) or grant your application access to remote data using the Global Security settings of the Flash Player. The second is easiest for the time being.
You can grant permission like this, right click on the application in the browser and choose Settings. In the Privacy tab (default) choose Advanced. On the page you are taken to click the link to Global Security Settings. Currently the link is this. In the section "always trust content from these locations" click the "Edit Locations" dropdown and choose "Add location". Then browse to and choose your project's "bin-debug" folder. Hit ok. Now go back and reload the page. If it worked and it will ALWAYS work then you will see "waiting for www.flexcapacitor.com in the browser footer" if you are using Firefox of course, not Safari bc safari doesn't feel like it needs to have a status bar. Elitest bastards.
So, email me if you have any questions. We'll take this to the next step in the next update. Please send feedback to judah at flexcapacitor dot com.