XML in Flash is Easy because RSS Feeds are Free [AS2] · Dec 31, 01:34 AM
The previous article explained how to insert flash into a Textpattern-powered site, but failed to integrate the content so that there would be no duplication. Instead, the CMS was used to re-publish content from our flash movie for search-bot and non-flash-browser compatibility. Doing it this way doesn’t really make sense. In fact, a compelling reason to use a CMS is to eliminate the need to duplicate content. Our new approach should be simple: put all content in the CMS, and have the CMS automatically output two versions: XML for Flash, HTML for everyone else.
Download the source-code files for this article
There are two ways to use XML content from Textpattern
- Create a custom section, page, and form that ouputs XML.
- Use Textpattern’s automatically generated RSS feed (RSS feeds are valid XML)
This article will focus on the second method because it requires far less work. In fact, because RSS feeds are automatically generated with Textpattern’s default installation, there won’t be any setup in Textpattern. When you install Textpattern, a section named article is automatically created. By default, all articles in this section will be included in the RSS feed located at http://www.example.com/rss (assuming you installed TextPattern in the root web directory of the example.com domain). You can also set any section of your site to be included in the feed: goto the sections tab and set the Syndicate option to yes.

Reading an RSS Feed in Flash
Luckily, someone has made this easy for us: An ActionScript code package that downloads and parses an RSS feed and sticks the information inside of an ActionScript object.
Download the ActionScript RSS Parser Package released by Cybozu Labs, Inc.
After you unzip the Cybozu file, copy the com folder to the folder with your flash file. Then you can use the following line of code to import the package into your Flash file:
import com.cybozuLab.rssParser.*;
This is the basic code structure for using the parser, follow the comments for explanation:
import com.cybozuLab.rssParser.*;// Create a new rssObj and initialize with the URL to the feedvar rssObj = new FetchingRss( "http://www.allflashwebsite.com/demo2/rss" );// define the function when loading is completedrssObj.onLoad = function( successFL, errMsg ) {if( successFL ) {// Do something with rssObj.getRssObject()} else {trace( errMsg );}}// start loadingrssObj.load();- Download this code: /files/code2.1.txt
Adding new Functionality to the Sample Code
The sample code for this article works off of the previous one. To add additional functionality, we will create a new movie called AFWRssViewer.swf and simply load this movie into home.swf using another instance of AFWLoader.

The screen-capture above shows home.fla with the changes applied. The selected movie is the new AFWLoader, called feedloader_mc, and it lives on the feedloader layer.
We also need to change a few lines of code inside the setPath() function of home.fla that will tell feedloader_mc to load the correct movie, or hide it when we navigate to a different link:
function setPath(path_arr) {link = path_arr[0] eq "" ? "home" : path_arr[0] ;url = "images/"+link+".jpg";loader_mc.loadMovie(url, link);// Load or Hide AFWRssViewer.swfif (link eq "home") {feedLoader_mc.loadMovie("AFWRssViewer.swf", "rss");feedLoader_mc._visible = true;} else {feedLoader_mc._visible = false;}}- Download this code: /files/code2.2.txt
Creating the AFWRssViewer.fla Movie
This movie is an RSS reader that displays one feed item at a time. The title and date of each item is displayed using some trippy text animation, and the body text fades in and out. There is also a non-functional button that would presumably take you to the link associated with the feed item.
Because the topic at hand is RSS, I won’t delve into a detailed explanation of the sample code. However, if you need clarification or additional detail, please post a comment. The following screenshot shows the timeline and stage of the completed AFWRssViewer.fla:

In the library, there are some components that I’ve thrown in to make the task simpler. First, AFWfx generates animated text: after it is instantiated, one call to setText(“my text”) starts the text animation. When placed on the stage, an instance of AFWfx looks like the letter W (see above image). Second, AFWTextSlider is used to display some text and also performs a fade-transition effect.
The code that follows ties together the aforementioned components. This code lives in frame 2 of AFWRssViewer.fla‘s main timeline:
import com.cybozuLab.rssParser.*;stop();var rssIntervalId = 0;var index = 0;var thisObj = this;// We'll populate this array with information from the feedvar arr_XMLHash:Array = new Array();// initialize feedvar rssObj = new FetchingRss( "http://www.allflashwebsite.com/demo2/rss" );// Initialize the AFWTextSlider on the stage// displays feed contentts_mc.setBackgroundAlpha(0);ts_mc.setSelectable(false);ts_mc.setControlsEnabled(false);ts_mc.loadStyle("afw.css");ts_mc.startTimerScroll();// define the function when loading is completedrssObj.onLoad = function( successFL, errMsg ) {if( successFL ) {thisObj.readRss();} else {trace( errMsg );}}// start loadingrssObj.load();// onLoad calls this function to process the feedfunction readRss() {var rssData:Object = rssObj.getRssObject();// process the rss data into arr_XMLHashfor( var i=0; i<rssData.channel.item.length; i++ ) {var post:Object = rssData.channel.item[i];var XMLHash:Object = {};XMLHash.date = post.pubdate.value;XMLHash.title = post.title.value;XMLHash.link = post.link.value;XMLHash.desc = post.description.value;trace("XMLHash:"); for (var a in XMLHash) { trace(" "+a+": "+XMLHash[a]); }arr_XMLHash.push(XMLHash);}// Display the first item in the feedif (arr_XMLHash.length>0) {fx2.setText(arr_XMLHash[0].title);fx1.setText(arr_XMLHash[index].date);ts_mc.fadeText(arr_XMLHash[0].desc);rssIntervalId = setInterval(this, "rssIntervalCallback", 13000);}}// This function displays the next feedfunction rssIntervalCallback() {if (arr_XMLHash.length == 0) return;index++;if (index >= arr_XMLHash.length) index = 0;fx2.setText(arr_XMLHash[index].title);fx1.setText(arr_XMLHash[index].date);ts_mc.fadeText(arr_XMLHash[index].desc);}// this function should theoretically display the link somehowfeedButton.onRelease = function () {trace("clicked");}- Download this code: /files/code2.3.txt
— Pickle
Comment
Basic Structure of a Flash Website [AS2] Content in Flash and Textpattern: Bridging the Gap with XML [AS2]
