Tutorials

Update: WordPress and Flash Integration part III

Wednesday, March 11th, 2009

Well, I finally had a little bit of free time and I wanted to rework all my wordpress and flash integrations stuff into ActionScript 3.  There were a couple of interesting things that came up while working on this as well.  You can’t tween the alpha property of a textfield created in actionscript (unless you use a simple hack that I found out in the Flash live-docs online).  You have to change the blendmode style to “LAYER”, or another type, as long as its not the default style type. Weird but at least I got it to work. Also, I was going to implement the tweens using TweenLite but they also have problems accessing textfield properities, too.

Here is the swf, and below is the actionscript 3:

wordpressflashex4

package  {
    import flash.display.MovieClip;
    import flash.display.BlendMode;
    import flash.events.Event;
    import flash.net.URLLoader;
    import flash.net.URLRequest;
    import flash.text.*;
    import fl.transitions.Tween;
    import fl.transitions.TweenEvent;
    import fl.transitions.easing.*;
 
    /*
    * Redo of scott rockers's wordpress to flash integration but in AS3 and as3wordpressFlash class file
    */
    public class AS3WordpressFlash extends MovieClip {
 
        public var i:uint = 0;
        public var titleList:XMLList;
        public var linkList:XMLList;
        public var tf:TextField;
        public var format:TextFormat;
        public var tweenIt:Tween;
        public var tweenIt2:Tween;
        public var theXML:XML;
        public var loader:URLLoader = new URLLoader();
 
        public function AS3WordpressFlash() {
            loader.addEventListener(Event.COMPLETE, loadXML);
            loader.load(new URLRequest("http://www.scottrockers.com/blog/wp-rss2.php"));
        }
 
        function loadXML(e:Event):void {
            theXML = new XML(e.target.data);
            titleList = theXML.channel.item.title;
            linkList = theXML.channel.item.link;
            createTextFields(titleList, linkList);
        }
 
        function createTextFields(titles:XMLList, links:XMLList):void {
            format = new TextFormat();
            format.font = "Arial";
            format.color = 0xFFFFFF;
            format.size = 14;
 
            for (i = 0; i < 5; i++) {
                tf = new TextField();
                tf.blendMode = BlendMode.LAYER;
                tf.width = 10;
                tf.selectable = false;
                tf.autoSize = TextFieldAutoSize.CENTER;
                tf.x = (stage.width)/2;
                tf.y = -20;
                tf.htmlText = "<a href="&quot;+ links[i] +&quot;" target="_blank">" + titles[i] + "</a>";
                tf.setTextFormat(format);
                addChild(tf);
                tweenIt = new Tween(tf, "y", Elastic.easeOut, -20, 50 + (i * 30), 30 + (i * 15), false);
                tweenIt2 = new Tween(tf, "alpha", Strong.easeOut, 0, 1, 100 + (i * 100), false);
            }
        }
    }
}

Update: WordPress and Flash Integration part II

Tuesday, January 27th, 2009

After working on accessing WordPress through the RSS feed with Flash, I have finally achieved what I was aiming for:  I wanted to be able to tween the headings of each post individually as well as make them links to the actual post.  Also, as you will see, this swf is dynamic meaning it will update itself to have the most recent blog post headings. Here is what I came up with:

I did come across a few interesting things. When accessing the titles of each heading, I used “.nodeValue”, but when accessing the links of the headings I had to use “theNodePath.toString()”. I thought this was weird because all the information looked the same inside each node in the XML.

I will use this technology on my blog as well as my Flash site, once I get some time to work on them. Hopefully soon, because I am pumped that I figured out how to do this.

Cya

Update: WordPress and Flash Integration part I

Friday, January 23rd, 2009

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