Packagenet.guttershark.model
Classpublic final dynamic class Model

The Model class provides shortcuts for parsing a model xml file as well as other model centric methods.


Example
Example model XML file:
 
  <?xml version="1.0" encoding="utf-8"?>
  <model>
     <content>
         <text id="helloWorldExample"><![CDATA[Hello]]></text>
         <text id="sparsley"><![CDATA[Some more example content]]></text>
     </content>
     <properties>
         <propset id="test">
             <textFormat id="theTextFormat" />
             <alpha>0.5</alpha>
             <xywh x="20" y="+30" width="+100" height="100" /> <!-- optional node for x/y/w/h -->
             <y>+30</y>
             <width>400</width>
             <alpha>+.4</alpha>
         </propset>
         <propset id="tfieldTest">
             <styleSheet id="colors3" />
             <htmlText><![CDATA[<p><span class="pink">hello</span> <span class="some">w</span>orld</p>]]></htmlText>
             <htmlText id="sparsley"/> <!-- optionally you can target a content/text node from the model, but not both. -->
         </propset>
     </properties>
     <assets>
         <asset libraryName="clayBanner1" source="clay_banners_1.jpg" preload="true" />
         <asset libraryName="clayBanner2" source="clay_banners_2.jpg" />
         <asset libraryName="clayWebpage" source="clay_webpage.jpg" />
         <group id="sounds">
             <asset libraryName="thesound" source="sound.mp3" path="sounds" />
         </group>
     </assets>
     <links>
         <link id="google" url="http://www.google.com" />
         <link id="rubyamf" url="http://www.rubyamf.org" />
         <link id="guttershark" url="http://www.guttershark.net" window="_blank" />
     </links>
     <attributes>
         <attribute id="someAttribute" value="the value" />
     </attributes>
     <services>
         <gateway id="amfphp" path="amfphp" url="http://localhost/amfphp/gateway.php" objectEncoding="3" />
         <service id="test" gateway="amfphp" endpoint="Test" limiter="true" attempts="4" timeout="1000" />
         <service id="foo" url="http://localhost/" attempts="4" timeout="1000" />
         <service id="sessionDestroy" path="sessiondestroy" url="http://tagsf/services/codeigniter/session/destroy" attempts="4" timeout="1000" responseFormat="variables" />
         <service id="ci" url="http://tagsf/services/codeigniter/" attempts="4" timeout="1000" responseFormat="variables" />
     </services>
     <stylesheets>
         <stylesheet id="colors">
         <![CDATA[
             .pink{color:#FF0066}
         ]]>
         </stylesheet>
         <stylesheet id="colors2">
         <![CDATA[
             .some{color:#FF8548}
         ]]>
         </stylesheet>
         <stylesheet id="colors3" mergeStyleSheets="colors,colors2" />
     </stylesheets>
     <textformats>
         <textformat id="theTF" font="Arial" color="0xFF0066" bold="true" />
     </textformats>
     <contextmenus>
         <menu id="menu1">
             <item id="home" label="home" />
             <item id="back" label="GO BACK" sep="true"/>
         </menu>
     </contextmenus>
  </model>
  



Public Properties
 PropertyDefined by
  flashvars : Object
A placeholder variable for the movies flashvars - this is not set by default, you need to set it in your controller.
Model
  sharedObject : SharedObject
A placeholder variable for the movies shared object - this is not set by default, override restoreSharedObject in your DocumentController, and set this property to a shared object.
Model
  xml : XML
The XML used as the model.
Model
Protected Properties
 PropertyDefined by
  assets : XMLList
Stores a reference to the <assets></assets> node in the model xml.
Model
  attributes : XMLList
Stores a reference to the <attributes></attributes> node in the model xml.
Model
  contents : XMLList
Stores a reference to the <content></content> node in the model xml.
Model
  inst : Model
[static] Singleton instance.
Model
  links : XMLList
Stores a reference to the <links></links> node in the model xml.
Model
  properties : XMLList
Stores a reference to the <properties></properties> node in the model xml.
Model
  services : XMLList
Stores a reference to the <services></services> node in the model xml.
Model
  stylesheets : XMLList
Stores a reference to the <stylesheets></stylesheets> node in the model xml.
Model
  textformats : XMLList
Stores a reference to the <textformats></textformats>
Model
Public Methods
 MethodDefined by
  
addPath(pathId:String, path:String):void
Add a URL path to the model - if ExternalInterface is available, it uses the guttershark javascript api.
Model
  
createContextMenuById(id:String):ContextMenu
Creates a new context menu with the context menu manager, from a menu that is defined in the model.
Model
  
disposeCache():void
Dispose of the internal cache.
Model
  
doesLinkExist(id:String):Boolean
Check whether or not a link is defined in the model.
Model
  
Flush the sharedObject property.
Model
  
getAssetByLibraryName(libraryName:String, prependSourcePath:String = null):Asset
Get an Asset instance by the library name.
Model
  
getAssetGroup(groupId:String):Array
Get an array of asset objects, defined by a group node.
Model
  
getAssetsByLibraryNames(... libraryNames):Array
Get an array of asset objects, from the provided library names.
Model
  
Returns an array of Asset instances from the assets node, that has a "preload" attribute set to true (preload='true').
Model
  
getAttribute(attributeID:String):String
Get the value from an attribute node.
Model
  
getContentById(id:String):String
Get's a piece of content from the content node in xml.
Model
  
getLink(id:String):URLRequest
Creates and returns a URLRequest from a link node.
Model
  
getLinkWindow(id:String):String
Get the window attribute value on a link node.
Model
  
getPath(... pathIds):String
Get a path concatenated from the given pathIds - if ExternalInterface is available, it uses the guttershark javascript api.
Model
  
getStyleSheetById(id:String):StyleSheet
Get a StyleSheet object by the node id.
Model
  
getTextFormatById(id:String):TextFormat
Get a TextFormat object by the node id.
Model
  
gi():Model
[static] Singleton access.
Model
  
initServices():void
Initializes all services defined in the model XML with the ServiceManager.
Model
  
isPathDefined(path:String):Boolean
Check whether or not a path has been defined.
Model
  
mergeStyleSheetsAs(newStyleId:String, ... styleIds):StyleSheet
Merge any number of style sheets declared in the model, as a new stylesheet with a unique id.
Model
  
navigateToLink(id:String):void
Navigates to a link.
Model
Protected Methods
 MethodDefined by
  
checkForXML():void
Check that the model xml was set on the singleton instance before any attempts to read the xml happens.
Model
Property detail
assetsproperty
protected var assets:XMLList

Stores a reference to the <assets></assets> node in the model xml.

attributesproperty 
protected var attributes:XMLList

Stores a reference to the <attributes></attributes> node in the model xml.

contentsproperty 
protected var contents:XMLList

Stores a reference to the <content></content> node in the model xml.

flashvarsproperty 
public var flashvars:Object

A placeholder variable for the movies flashvars - this is not set by default, you need to set it in your controller.

instproperty 
protected static var inst:Model

Singleton instance.

linksproperty 
protected var links:XMLList

Stores a reference to the <links></links> node in the model xml.

propertiesproperty 
protected var properties:XMLList

Stores a reference to the <properties></properties> node in the model xml.

servicesproperty 
protected var services:XMLList

Stores a reference to the <services></services> node in the model xml.

sharedObjectproperty 
public var sharedObject:SharedObject

A placeholder variable for the movies shared object - this is not set by default, override restoreSharedObject in your DocumentController, and set this property to a shared object.

stylesheetsproperty 
protected var stylesheets:XMLList

Stores a reference to the <stylesheets></stylesheets> node in the model xml.

textformatsproperty 
protected var textformats:XMLList

Stores a reference to the <textformats></textformats>

xmlproperty 
xml:XML  [read-write]

The XML used as the model.

Implementation
    public function get xml():XML
    public function set xml(value:XML):void
Method detail
addPath()method
public function addPath(pathId:String, path:String):void

Add a URL path to the model - if ExternalInterface is available, it uses the guttershark javascript api. Otherwise it's stored in a local dictionary.

Parameters
pathId:String — The path identifier.
 
path:String — The path.

Example
Using path logic with the model.
   public class Main extends DocumentController
   {
   
       //only called in standalone player, otherwise you must
       //add paths through javascript - see the guttershark/lib/js/guttershark.js file.
       override protected function initPathsForStandalone():void
       {
           ml.addPath("root","./");
           ml.addPath("assets",ml.getPath("root")+"assets/");
           ml.addPath("bitmaps",ml.getPath("root","assets")+"bitmaps/");
           testPaths();
       }
       
       //illustrates how the "getPath" function works.
       private function testPaths():void
       {
           trace(ml.getPath("root")); // -> ./
           trace(ml.getPath("assets")); // -> ./assets/
           trace(ml.getPath("bitmaps")); // -> ./assets/bitmaps/
       }
   }
   

checkForXML()method 
protected function checkForXML():void

Check that the model xml was set on the singleton instance before any attempts to read the xml happens.

createContextMenuById()method 
public function createContextMenuById(id:String):ContextMenu

Creates a new context menu with the context menu manager, from a menu that is defined in the model.

Parameters
id:String — The id of the context menu to build and return.

Returns
ContextMenu
disposeCache()method 
public function disposeCache():void

Dispose of the internal cache. The internal cache caches textformats and stylesheets.

doesLinkExist()method 
public function doesLinkExist(id:String):Boolean

Check whether or not a link is defined in the model.

Parameters
id:String — The link id.

Returns
Boolean
flushSharedObject()method 
public function flushSharedObject():void

Flush the sharedObject property.

getAssetByLibraryName()method 
public function getAssetByLibraryName(libraryName:String, prependSourcePath:String = null):Asset

Get an Asset instance by the library name.

Parameters
libraryName:String — The libraryName of the asset to create.
 
prependSourcePath:String (default = null) — The path to append to the source property of the asset.

Returns
Asset
getAssetGroup()method 
public function getAssetGroup(groupId:String):Array

Get an array of asset objects, defined by a group node.

Parameters
groupId:String — The id of the group node.

Returns
Array
getAssetsByLibraryNames()method 
public function getAssetsByLibraryNames(... libraryNames):Array

Get an array of asset objects, from the provided library names.

Parameters
... libraryNames — An array of library names.

Returns
Array
getAssetsForPreload()method 
public function getAssetsForPreload():Array

Returns an array of Asset instances from the assets node, that has a "preload" attribute set to true (preload='true').

Returns
Array
getAttribute()method 
public function getAttribute(attributeID:String):String

Get the value from an attribute node.

Parameters
attributeID:String — The id of an attribute node.

Returns
String
getContentById()method 
public function getContentById(id:String):String

Get's a piece of content from the content node in xml.

Parameters
id:String — The text id.

Returns
String
getLink()method 
public function getLink(id:String):URLRequest

Creates and returns a URLRequest from a link node.

Parameters
id:String — The id of the link node.

Returns
URLRequest
getLinkWindow()method 
public function getLinkWindow(id:String):String

Get the window attribute value on a link node.

Parameters
id:String — The id of the link node.

Returns
String
getPath()method 
public function getPath(... pathIds):String

Get a path concatenated from the given pathIds - if ExternalInterface is available, it uses the guttershark javascript api. Otherwise it's stored in a local dictionary.

Parameters
... pathIds — An array of pathIds whose values will be concatenated together.

Returns
String
getStyleSheetById()method 
public function getStyleSheetById(id:String):StyleSheet

Get a StyleSheet object by the node id.

Parameters
id:String — The id of the stylesheet node to grab from the model.

Returns
StyleSheet
getTextFormatById()method 
public function getTextFormatById(id:String):TextFormat

Get a TextFormat object by the node id.

Supports these attributes:

Parameters
id:String

Returns
TextFormat
gi()method 
public static function gi():Model

Singleton access.

Returns
Model
initServices()method 
public function initServices():void

Initializes all services defined in the model XML with the ServiceManager.

isPathDefined()method 
public function isPathDefined(path:String):Boolean

Check whether or not a path has been defined.

Parameters
path:String

Returns
Boolean
mergeStyleSheetsAs()method 
public function mergeStyleSheetsAs(newStyleId:String, ... styleIds):StyleSheet

Merge any number of style sheets declared in the model, as a new stylesheet with a unique id. The new stylesheet is returned to you, and can be accessed again through the getStyleSheetById method. You can also declare merged style sheets in the model through xml. There is an example in examples/model/model.xml.

Parameters
newStyleId:String — The id to name the new merged stylesheet.
 
... styleIds — An array of style ids that are defined in the model.

Returns
StyleSheet
navigateToLink()method 
public function navigateToLink(id:String):void

Navigates to a link.

Parameters
id:String — The link id.