Update: WordPress and Flash Integration part I

I’ve been working on integrating my WordPress blog with Flash for the last couple days now whenever I had some free time, and I have some great things to show.  I will try explain the best I can about what I am doing.  If I do this correctly, and I think I am, then I will be able to use my WordPress blog as a complete CMS for my flash website.

If you have a WordPress blog already setup, then you can do all this easy too.  All WordPress blogs have a RSS feed built into them, so what I did was access that php file that creates the RSS feed (which renders out as XML),  and thats all Flash needs to have to be able to do what we want.  The best part is that the .swf file updates itself automatically anytime it is called which makes the whole thing dynamic.

Click on the image below to see an example that retrieves every heading to every post on my blog and puts them into a simple list component.

Here is the code I used in the .FLA, its AS2:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
// Create new XML Object and set ignoreWhite true
var theXML:XML = new XML();
theXML.ignoreWhite = true;
 
//the function to check to see if the xml file was loaded
theXML.onLoad = function(success) {
     if (success) {
          trace('Your XML file was loaded! See its right here:' + '\n\n' + this.toString() + '\n\n');
          processXML(theXML);
     } else {
          trace('Your XML file was not loaded');
     }
}
 
//where to find the the xml file and loads it
//just change the url to your rss url
theXML.load("http://www.scottrockers.com/blog/wp-rss2.php");
 
//function that puts all the posts' headers into the list component
function processXML(xmlInfo) {
     // xmlInfo is now a reference to the XML
     // object where our information is stored
     for (var n = 0; n < xmlInfo.firstChild.firstChild.childNodes.length; n++) {
          if (xmlInfo.firstChild.firstChild.childNodes[n].nodeName == "item") {
               trace(xmlInfo.firstChild.firstChild.childNodes[n].firstChild.firstChild.nodeValue);
               theList.addItem(xmlInfo.firstChild.firstChild.childNodes[n].firstChild.firstChild.nodeValue);
          } else {
               //these are the parent nodes, do not print them
               //trace(xmlInfo.firstChild.firstChild.childNodes[n].firstChild.nodeValue);
          }
     }
}

I can even access certain categories by changing: theXML.load(“http://www.scottrockers.com/blog/wp-rss2.php”); to theXML.load(“http://www.scottrockers.com/blog/?cat=4&feed=rss2″);

Click on the image below to see an example that retrieves only headings to posts under the category “Portfolio” and puts them into a simple list component.

Since I now know how to access those node values then I will also be able to do anything with them, such as animate them on to the stage, make them links, etc. I am sooooo pumped about this.

Cya

Tags: , ,

3 Responses to “Update: WordPress and Flash Integration part I”

  1. lengly says:

    hit great stuff right here. i tried copying your code directly into flash cs3 and i come up with two errors

    Unexpected ‘}’ encountered on line 31

    and

    Unexpected ‘lt’ encountered line 23

    any idea why?

  2. admin says:

    Hello, I have updated the code, wordpress changed < to &alt; in the text so thats was why it was messing up, thanks for testing:). I have fixed the issue. Also, make sure to add a List component to your library when testing this in Flash and also make sure to give it the instance name of theList.

    Scott

  3. Nice post, thanks for adding it. It was great to read on this boring day!

Leave a Reply