This pure AS3 tutorial will show you how to make a simple RSS item title visualization using Papervision3D and a couple MinimalComps, HSlider and Knob.
Needed:
RSS Tutorial Source Code
PaperVision3D
MinimalComps
Adobe XML Syndication Library (as3syndicationlib)
First we'll create an RSSConsumer class for retrieving and parsing an RSS feed. This class is a bare-bones utility on which you can add functionality for other projects. For now it'll be used to retrieve an RSS 2.0 feed, but Adobe's syndication library contains a lot more functionality.
-
package
-
{
-
import com.adobe.xml.syndication.rss.RSS20;
-
import com.adobe.xml.syndication.rss.Channel20;
-
import com.adobe.xml.syndication.rss.Image20;
-
import com.adobe.xml.syndication.rss.Item20;
-
import com.adobe.xml.syndication.rss.Cloud;
-
-
import flash.display.Sprite;
-
import flash.events.Event;
-
import flash.events.IOErrorEvent;
-
import flash.events.SecurityErrorEvent;
-
-
import flash.net.*;
-
-
public class RSSConsumer extends Sprite
-
{
-
public static const ITEMS_RETURNED:String = "items_returned";
-
public static const ERROR:String = "error";
-
-
private var myRSS20:RSS20;
-
-
private var __items:Array = new Array();
-
-
public function RSSConsumer() {}
-
-
public function loadRSS(xmlLink:String=null):void
-
{
-
var xmlLoader:URLLoader = new URLLoader();
-
xmlLoader.addEventListener(Event.COMPLETE, onResult);
-
var urlReq:URLRequest = new URLRequest(xmlLink);
-
xmlLoader.load(urlReq);
-
}
-
-
private function onResult(event:Event):void
-
{
-
var loader:URLLoader = URLLoader(event.target);
-
-
myRSS20 = new RSS20();
-
-
var xmlData:XML = XML(loader.data);
-
myRSS20.populate(xmlData);
-
items = myRSS20.items;
-
-
dispatchEvent(new Event(ITEMS_RETURNED));
-
}
-
-
private function onIOError(event:IOErrorEvent):void
-
{
-
dispatchEvent(new Event(ERROR));
-
}
-
-
private function onSecurityError(event:SecurityErrorEvent):void
-
{
-
dispatchEvent(new Event(ERROR));
-
}
-
-
public function get items():Array { return __items; }
-
public function set items(value:Array):void
-
{
-
__items = value;
-
}
-
}
-
}
Now that we have out items, we can break out Papervision3D and make them scrollable.
-
package
-
{
-
import gs.TweenMax;
-
import gs.easing.*;
-
-
import com.adobe.xml.syndication.rss.Item20;
-
-
import org.papervision3d.materials.special.Letter3DMaterial;
-
import org.papervision3d.typography.fonts.HelveticaBold;
-
import org.papervision3d.typography.Text3D;
-
import org.papervision3d.events.InteractiveScene3DEvent;
-
-
import com.bit101.components.*;
-
-
import flash.display.Sprite;
-
import flash.events.Event;
-
import flash.events.MouseEvent;
-
import flash.events.KeyboardEvent;
-
-
import org.papervision3d.cameras.Camera3D;
-
import org.papervision3d.materials.*;
-
import org.papervision3d.objects.DisplayObject3D;
-
import org.papervision3d.render.BasicRenderEngine;
-
import org.papervision3d.scenes.*;
-
import org.papervision3d.view.Viewport3D;
-
import org.papervision3d.view.BasicView;
-
-
[SWF(backgroundColor="#000000",frameRate="40")]
-
public class RSSNav extends Sprite
-
{
-
private var cameraTarget:DisplayObject3D = DisplayObject3D.ZERO;
-
private var myCamera:Camera3D;
-
private var myScene:Scene3D;
-
private var render:BasicRenderEngine;
-
private var view:Viewport3D;
-
private var pivot:DisplayObject3D;
-
private var pv3dStage:Sprite = new Sprite();;
-
private var totalDistance:Number;
-
private var currentItem:Number;
-
private var newZ:Number = 0;
-
private var oldZ:Number;
-
private var increment:Number = 2000;
-
-
// Here's our RSS Consumer
-
private var consumer:RSSConsumer;
-
-
// These are Minimal Comps
-
private var knob:Knob;
-
private var hslider:HSlider;
-
-
private var itemColl:Array;
-
private var rssItemColl:Array;
-
-
public function RSSNav()
-
{
-
createScene();
-
loadRSS();
-
}
-
-
private function createScene():void
-
{
-
myCamera = new Camera3D();
-
myCamera.fov = 35;
-
myCamera.y = 200;
-
-
addChild(pv3dStage);
-
-
view = new Viewport3D(3000, 3000, true, true);
-
view.interactive = true;
-
pv3dStage.addChild(view);
-
-
myScene = new Scene3D();
-
render = new BasicRenderEngine();
-
pivot = new DisplayObject3D();
-
-
stage.addEventListener(KeyboardEvent.KEY_DOWN, onKeyboard);
-
}
-
-
private function loadRSS():void
-
{
-
consumer = new RSSConsumer();
-
consumer.addEventListener(RSSConsumer.ITEMS_RETURNED, onData);
-
consumer.loadRSS("http://www.mikebritton.com/index.xml");
-
}
-
-
private function createNavigation():void
-
{
-
hslider = new HSlider(this);
-
hslider.name = "hslider";
-
hslider.addEventListener(Event.CHANGE, onUpdate);
-
hslider.addEventListener(MouseEvent.CLICK, deselect);
-
hslider.x = (stage.stageWidth/2)-hslider.width/2;
-
hslider.y = stage.stageHeight / 3;
-
hslider.backClick = true;
-
addChild(hslider);
-
-
knob = new Knob(this);
-
knob.name = "knob";
-
knob.setSize(100, 100);
-
knob.addEventListener(Event.CHANGE, onUpdate);
-
knob.addEventListener(MouseEvent.CLICK, deselect);
-
knob.x = (stage.stageWidth/2)-knob.width/2;
-
knob.y = 120;
-
knob.visible = true;
-
addChild(knob);
-
}
-
-
private function deselect(event:MouseEvent):void
-
{
-
for (var i:int = 0; i <itemColl.length; i++) {
-
if (i != currentItem) {
-
InteractiveText3D(itemColl[i]).reveal();
-
}
-
}
-
}
-
-
private function distinguish():void
-
{
-
InteractiveText3D(itemColl[currentItem]).reveal();
-
-
for (var i:int = 0; i 0) {
-
rssItemColl = event.target.items;
-
itemColl = new Array();
-
currentItem = 0;
-
totalDistance = (rssItemColl.length * increment)+1000;
-
-
for (var i:int = 0; i 0) {
-
newZ = (event.target.value * .01) * totalDistance;
-
} else {
-
newZ = 0;
-
}
-
-
var cameraTweenObject:Object = { ease:Quad.easeOut,z:newZ };
-
TweenMax.to(myCamera, 2, cameraTweenObject);
-
-
distinguish();
-
}
-
-
-
private function onKeyboard(event:KeyboardEvent):void
-
{
-
switch (event.keyCode) {
-
case 39: // Right arrow
-
if (currentItem<rssItemColl.length-1)
-
currentItem++;
-
break;
-
case 38: // Up arrow
-
if (currentItem0)
-
currentItem--;
-
break;
-
case 40: // Down arrow
-
if (currentItem>0)
-
currentItem--;
-
break;
-
}
-
hslider.value = ((currentItem * increment) / totalDistance) * 100;
-
}
-
}
-
}
Set RSSNav to compile and give it a shot. As you can see when you preview, you can scroll through the RSS items with Knob, HSlider or the keyboard.
Next time, we'll expand on this idea and have even more fun with Papervision 3D.




