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

Comments

8/10/2009 2:06:22 PM #


The content on this site is unique. A good work done related to tutorials and must be carried on.

Web design United Kingdom

5/13/2010 8:45:15 AM #

Why SiteStream?

Why SiteStream?

FARMCode.org