Packagegs.model
Classpublic class Model

The Model class contains shortcuts for parsing a model xml file.


Example
Example model XML file:
 
  <?xml version="1.0" encoding="utf-8"?>
  <model>
     <fonts>
         <font libraryName="Arial_Test" inSWF="fonts" />
         <group id="myGroup">
             <font libraryName="Helvetica Neueu Bold Condensed" />
         </group>
     </fonts>
     
     <assets>
         <asset libraryName="clayBanner1" source="clay_banners_1.jpg" preload="true" />
         <asset libraryName="clayBanner2" source="clay_banners_2.jpg" />
         <asset libraryName="clayBanner3" source="clay_banners_3.jpg" forceReload="true" />
         <asset libraryName="clayWebpage" source="clay_webpage.jpg" />
         <asset libraryName="rssFeed" source="http://codeendeavor.com/feed" forceType="xml" />
         <asset libraryName="fonts" source="fonts.swf" preload="true" />
         <group id="sounds">
             <asset libraryName="thesound" source="sound.mp3" path="sounds" />
         </group>
     </assets>
     
     <captions>
         <group id="spiritVideo">
              <caption time="3" duration="3" bgcolor="0x222222">
                   <![CDATA[
                       <span class="body">bob lob law</span>
                   ]]>
              </caption>
              <caption time="8" duration="3" bgcolor="0x222222">
                   <![CDATA[
                       <span class="body">bob lob law</span>
                   ]]>
              </caption>
         </group>
     </captions>
     
     <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" />
         <link id="googleFromStringId" stringId="googleInStrings" />
     </links>
     
     <attributes>
         <attribute id="someAttribute" value="the value" />
         <attribute id="someAttributeFromStrings" stringId="someAttributeValueStringId" />
     </attributes>
     
     <textAttributes>
         <attribute id="myTextAttribute1" autoSize="left" antiAliasType="advanced"
             styleSheetId='someStyleSheetId' textFormatId='someTextFormatId'
             stringId='someStringId' wrapInBodySpan='true' selectable='false' border='false'
             multiline='false' embedFonts='true'
         />
         <attribute id="myTextAttribute2" styleSheetId='someStyleSheetId' /> <!-- you don't have to use every attribute, it will only apply what's here. -->
     </textAttributes>
     
     <services>
         <http>
             <service id="google" url="http://www.google.com/" retries="1" timeout="1500" >
                 <call id="home" url="" method="GET||POST" responseFormat="text" retries="1" timeout="1500" />
             </service>
             <service id="codeendeavor" url="http://www.codeendeavor.com/" retries="1" timeout="1500" >
                 <call id="article814" url="archives/814" method="GET||POST" responseFormat="text" retries="1" timeout="1500" />
             </service>
         </http>
         <remoting>
             <service id="amfphp" gateway="http://guttershark_amfphp/gateway.php" encoding="3" timeout="3000" retries="1" >
                 <call id="Echoer.echoString" endpoint="Echoer" method="echoString" />
                 <call id="Echoer.echoObject" endpoint="Echoer" method="echoObject" encoding="3" timeout="3000" retries="1" />
             </service>
         </remoting>
         <soap>
             <service id="resolveIP" wsdl="http://ws.cdyne.com/ip2geo/ip2geo.asmx?WSDL" timeout="3000" retries="1" />
         </soap>
     </services>
     
     <security>
         <policyfiles>
             <crossdomain url="http://www.codeendeavor.com/crossdomain.xml" />
         </policyfiles>
         <xscript>
             <domain name="macromedia.com" />
             <domain name="\ />
             <domain name="192.168.1.1" />
         </xscript>
     </security>
     
     <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>
     
     <properties>
         <-- See examples/model_properties for more information on cast types. -->
         <clip x="[int]10" y="[int]10" alpha="[number]1">
             <clip2 x="[int]0" y="[int]0" alpha="[number]1" />
             <clip3 x="[int]200" y="[int]0" alpha="[number].5" visible="[bool]false" />
         </clip>
     </properties>
  </model>
  

Examples are in the guttershark repository.



Public 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
  captions : XMLList
Stores a reference to the <captions></captions> node in the model xml.
Model
  fonts : XMLList
Stores a reference to the <fonts></fonts> node in the model xml.
Model
  id : String
The id of this model.
Model
  links : XMLList
Stores a reference to the <links></links> node in the model xml.
Model
  security : XMLList
Stores a reference to the <security></security> node in the model xml.
Model
  services : XMLList
Stores a reference to the <services></services> node in the model xml.
Model
  strings : Strings
A placeholder for an instance of a Strings object.
Model
  stylesheets : XMLList
Stores a reference to the <stylesheets></stylesheets> node in the model xml.
Model
  textAttributes : XMLList
Stores a reference to the <textAttributes></textAttributes> node in the model xml.
Model
  textformats : XMLList
Stores a reference to the <textformats></textformats>
Model
  xml : XML
The XML used as the model.
Model
Public Methods
 MethodDefined by
  
addPath(pathId:String, path:String):void
Add a path to the model.
Model
  
Allows a domain for cross scripting this swf.
Model
  
applyProperties(obj:*, xml:*):void
Apply a hierarchy of property values to an object.
Model
  
attrAsBool(attributeID:String):Boolean
A shortcut method to get an attribute as a boolean.
Model
  
attrAsInt(attributeID:String):int
A shortcut method to get an attribute as an integer.
Model
  
attrAsNumber(attributeID:String):Number
A shortcut method to get an attribute as a number.
Model
  
clearCache():void
Clears the internal cache.
Model
  
dispose():void
Dispose of this model.
Model
  
doesLinkExist(id:String):Boolean
Check whether or not a link is defined in the model.
Model
  
get(id:String):Model
[static] Get a model instance.
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
  
getCaptionsByGroupId(groupId:String):*
Returns a captioning set for flv captioning.
Model
  
getColorAs0xHexString(selector:String):String
Get a color in hex with 0x, (0xff0066).
Model
  
getColorAsInt(selector:String):int
Get's a color defined in the "colors" stylesheet.
Model
  
getColorAsPoundHexString(selector:String):String
Get a color in hex with #, (#ff0066).
Model
  
getHTTPCallById(serviceId:String, callId:String):HTTPCall
Get an HTTPCall instance by id.
Model
  
Get an HTTPService by id.
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.
Model
  
getRemotingCallById(serviceId:String, callId:String):RemotingCall
Get a remoting call by service, and call id.
Model
  
Get a remoting service by id.
Model
  
Get a soap service by id.
Model
  
getStyleSheetById(id:String):StyleSheet
Get a StyleSheet object by the node id.
Model
  
Get a text attributes.
Model
  
getTextFormatById(id:String):TextFormat
Get a TextFormat object by the node id.
Model
  
isPathDefined(path:String):Boolean
Check whether or not a path has been defined.
Model
  
load(model:String, complete:Function, ioerror:Function = null, securityerror:Function = null):void
Load an xml file to use as the model xml.
Model
  
Loads all the security policy files specified in the model.
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
  
registerFonts(groupId:String = null):void
Register declared fonts from the model.
Model
  
set(id:String, ml:Model):void
[static] Set a model instance.
Model
  
traceFonts(groupId:String = null):*
Traces information about fonts that will be registered when calling the registerFont method.
Model
  
unset(id:String):void
[static] Unsets (deletes) a model instance.
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
public var assets:XMLList

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

attributesproperty 
public var attributes:XMLList

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

captionsproperty 
public var captions:XMLList

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

fontsproperty 
public var fonts:XMLList

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

idproperty 
public var id:String

The id of this model.

linksproperty 
public var links:XMLList

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

securityproperty 
public var security:XMLList

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

servicesproperty 
public var services:XMLList

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

stringsproperty 
public var strings:Strings

A placeholder for an instance of a Strings object. This is never set automatically, it's a placeholder to you to set it yourself.

stylesheetsproperty 
public var stylesheets:XMLList

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

textAttributesproperty 
public var textAttributes:XMLList

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

textformatsproperty 
public 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 path to the model.

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

Example
Using path logic with the model.
 
   public class Main extends DocumentController
   {
       override protected function initPaths():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/
       }
   }
   

allowCrossScriptingDomains()method 
public function allowCrossScriptingDomains():void

Allows a domain for cross scripting this swf.

This is specifically for cases where a swf needs to allow an outer swf access (Security.allowDomain()).

applyProperties()method 
public function applyProperties(obj:*, xml:*):void

Apply a hierarchy of property values to an object. The xml should be a reference to the root node that corresponds to the object provided, it recurses down the xml in parallel with the object chain and sets property values.

Parameters
obj:* — The root object.
 
xml:* — The root xml.
attrAsBool()method 
public function attrAsBool(attributeID:String):Boolean

A shortcut method to get an attribute as a boolean.

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

Returns
Boolean
attrAsInt()method 
public function attrAsInt(attributeID:String):int

A shortcut method to get an attribute as an integer.

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

Returns
int
attrAsNumber()method 
public function attrAsNumber(attributeID:String):Number

A shortcut method to get an attribute as a number.

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

Returns
Number
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.

clearCache()method 
public function clearCache():void

Clears the internal cache.

The internal cache caches textformats and stylesheets.

dispose()method 
public function dispose():void

Dispose of this model.

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
get()method 
public static function get(id:String):Model

Get a model instance.

Parameters
id:String — The id of the model.

Returns
Model
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 prepend 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
getCaptionsByGroupId()method 
public function getCaptionsByGroupId(groupId:String):*

Returns a captioning set for flv captioning.

Parameters
groupId:String — The captioning group id.

Returns
*
getColorAs0xHexString()method 
public function getColorAs0xHexString(selector:String):String

Get a color in hex with 0x, (0xff0066).

Parameters
selector:String — The select from the "colors" stylesheet.

Returns
String

See also

getColorAsInt()method 
public function getColorAsInt(selector:String):int

Get's a color defined in the "colors" stylesheet. There must be a stylesheet defined with the id of "colors".

Parameters
selector:String — The selector from "colors" the stylesheet.

Returns
int

Example
A colors stylesheet definition:
 
   <stylsheets>
       <stylesheet id="colors">
       <![CDATA[
           .pink{color:#ff0066}
       ]]>
       </stylesheet>
   </stylesheets>
   

Using this method:
 
   var color:int=Model.gi().getColorAsInt(".pink");
   

getColorAsPoundHexString()method 
public function getColorAsPoundHexString(selector:String):String

Get a color in hex with #, (#ff0066).

Parameters
selector:String — The select from the "colors" stylesheet.

Returns
String

See also

getHTTPCallById()method 
public function getHTTPCallById(serviceId:String, callId:String):HTTPCall

Get an HTTPCall instance by id.

Parameters
serviceId:String — The service id.
 
callId:String — The call id.

Returns
HTTPCall
getHTTPServiceById()method 
public function getHTTPServiceById(id:String):HTTPService

Get an HTTPService by id.

Parameters
id:String — The service id.

Returns
HTTPService
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.

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

Returns
String
getRemotingCallById()method 
public function getRemotingCallById(serviceId:String, callId:String):RemotingCall

Get a remoting call by service, and call id.

Parameters
serviceId:String — The id of the remoting call.
 
callId:String

Returns
RemotingCall
getRemotingServiceById()method 
public function getRemotingServiceById(id:String):RemotingService

Get a remoting service by id.

Parameters
id:String — The service id.

Returns
RemotingService
getSoapServiceById()method 
public function getSoapServiceById(id:String):SoapService

Get a soap service by id.

Parameters
id:String — The soap service id.

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

Get a StyleSheet object by the node id.

There is one extra "feature" that this can do - setting the proper font names for you, based off of the "font" or "fontFamily".

If you specify a "font" style, this will look for a font defined in the model, grab it out of the library, and use font.fontName as the "fontFamily" style.

If you specify the "fontFamily" style, this will use the asset manager to try and grab your font out, and replace what you have defined for the "fontFamily" style with the proper name.

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

Returns
StyleSheet
getTextAttributeById()method 
public function getTextAttributeById(id:String):TextAttributes

Get a text attributes.

Parameters
id:String — The id of a text attribute node.

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

Get a TextFormat object by the node id.

Supports these attributes:

Parameters
id:String

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

Check whether or not a path has been defined.

Parameters
path:String

Returns
Boolean
load()method 
public function load(model:String, complete:Function, ioerror:Function = null, securityerror:Function = null):void

Load an xml file to use as the model xml.

Parameters
model:String — The model xml file name.
 
complete:Function — A callback function for on complete of the xml load.
 
ioerror:Function (default = null) — A callback function to handle ioerrors.
 
securityerror:Function (default = null) — A callback function to handle security errors.
loadPolicyFiles()method 
public function loadPolicyFiles():void

Loads all the security policy files specified in the model.

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.

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.
registerFonts()method 
public function registerFonts(groupId:String = null):void

Register declared fonts from the model. If no group id is specified, all fonts declared are registered.

Parameters
groupId:String (default = null) — Optionally register fonts that were declared as part of a specific group.
set()method 
public static function set(id:String, ml:Model):void

Set a model instance.

Parameters
id:String — The model id.
 
ml:Model — The model instance.
traceFonts()method 
public function traceFonts(groupId:String = null):*

Traces information about fonts that will be registered when calling the registerFont method.

Parameters
groupId:String (default = null) — Optionally trace fonts that were declared as part of a specific group.

Returns
*
unset()method 
public static function unset(id:String):void

Unsets (deletes) a model instance.

Parameters
id:String