Why SiteStream?

by Tom Byrne 13. May 2010 07:14

SiteStream is an AS3 library for parsing XML into first-class objects, read a basic tutorial here.

SiteStream aims to solve certain inflexibilities of AS3. It is not a replacement for flashvars or Remoting/AJAX. It is better to consider it a non-compiled part of your application.

Consider these traits of AS3/Flash Player:

  • AS3 is strongly typed and pre-compiled, meaning that code dependancies will automatically get bundled together without special provisions to split them into seperate SWFs (like Flash Builder's 'Module's).
  • The Flash Player offers no control over the order in which parts of a SWF are loaded (I have a feeling they do this for server compatibility reasons).
  • Which of these SWFs to load, and in what order, enerally depends on which parts of your app the user visits.

These SWFs quickly become unmanagable, SiteStream provides a simple way of loading the appropriate SWF at the appropriate time.

The XML files themselves are also only loaded when needed by the app.

Whilst AS3 (and other C-based languages) are great for fine functional programming, XML based languages have long been recognised as stronger in broader architectural programming situations (e.g. MXML, XAML, etc). SiteStream allows the core displays, data-sources and visual assets of your app to be configured and assembled in XML.

The benefits of doing this in a non-compiled format (as opposed to MXML):

  • Implicit management of SWF loading.
  • Easily switch from XML files to dynamically generated XML output (from any number of existing CMSs).

After saying all of this, SiteStream doesn't impose any rules upon it's use in your applications, and if you want to use it purely for the loading of data structures you're perfectly free to do so.

Tags:
Categories: Flash | SiteStream

Tutorial 1: Introducing SiteStream

by Tom Byrne 1. May 2009 11:27

This is part one of a three part tutorial.

SiteStream is an AS3 library for parsing XML into first-class objects. All the information needed for the parsing process is in the XML syntax and there is no need to write any additional code.
XML data sources can reference each other, allowing data to load in piece by piece depending on what your flash app requires.
SiteStream also has the powerful feature of being able to specify other SWFs which contain the classes used, so that your class libraries are loaded invisibly only when required.

  1. Simple XML Syntax Example
  2. Retrieving an item
  3. Download Source

1. Simple XML Syntax Example

SiteStream XML allows you to write object structures in XML format. Each XML Node represents an Actionscript object.

Look at the first child tag in the XML below, it has the following characteristics:

  • It’s node name “Shape” is the name of the Class which will be used for this object
  • It’s namespace “displayPackage” is a package identifier, all package identifiers have a listing in the root tag which specifies the full package for the class.
  • It has an attribute “id” with the value “mask”, this specifies both the property of the parent object that this object should fill and the SiteStream name used in SiteStream paths.
  • It has an attribute “alpha” with a value “0.5”, this is how simple properties are set into objects.

This example creates a Sprite, it then creates a Shape and sets it as the Sprite's mask, then it creates a Rectangle (100x100) which it sets as the Shape's scrollRect.

<displayPackage:Sprite id="root"
displayPackage="flash.display.*"
geomPackage="flash.geom.*"
>
<displayPackage:Shape id="mask" alpha="0.5">
<geomPackage:Rectangle id="scrollRect" x="0" y="0" width="100" height="100"/>
</displayPackage:Shape>
</displayPackage:Sprite>

2. Retrieving an item

The following example has an XML data source which creates an array of MyClass objects (an arbitrary class as an example), the code shows how an item could be retrieved from the array. Notice that the class must be included in the code (more on that in Part 2). The MyClass Class can be seen at the bottom of this post.

myXML.xml:

<Array id="root"
myPackage="myPackage.*">
<myPackage:MyClass id="item1"/>
<myPackage:MyClass id="item2"/>
<myPackage:MyClass id="item3"/>
<myPackage:MyClass id="item4"/>
<myPackage:MyClass id="item5"/>
</Array>

SiteStreamTest.as:

package
{
import org.farmcode.siteStream.SiteStream;
import flash.display.Sprite;
import myPackage.MyClass;
public class SiteStreamTest extends Sprite
{
public function SiteStreamTest(){
var includeClass:Class = MyClass;
var siteStream:SiteStream = new SiteStream();
siteStream.rootURL = "myXML.xml";
siteStream.getObject("root/item2",onSuccess);
}
private function onSuccess(e:MyClass):void{
trace("Item 2 retrieved");
}
}
}


MyClass.as:

package myPackage
{ public class MyClass { public var colour:Number; public var childObject:MyClass; } }

 

3. Download Source


Goto Tutorial 2 >

Categories: Flash | SiteStream