class com.senocular.xml

XMLDefinition

Class Information

Description
The XMLDefinition class contains static methods for working with XML-based definitions. XML-based definitions are XML structures which mimic object relationships in Flash.

There are 3 kinds of elements and 1 attribute for special uses, each of which defined in the com.senocular.xml.XMLDefinition namespace. They are:
  • property (element)
  • call (element)
  • arguments (element)
  • name (attribute)
The property element is used to access an existing property of an object. For example, you may want to reference the transform property of a MovieClip instance defined in XML rather than redefine it. In that case you would use the property element to access that property's existing value rather than provide a new value to be set for the MovieClip's transform property. This element uses one attribute, name, to determine the name of the property being accessed.

The call element is used to call methods within objects. Like the property element, it too uses the name attribute to identify the class member (in this case a method) to be accessed. This would be useful for calling drawing methods on a display object. Method arguments are handled through the arguments element.

The arguments element is used in combination with class definitions or method calls. For class definitions (elements representing class instances) the arguments element contains the arguments for that instance's constructor call. For method calls, the arguments element's children are used as arguments for that method. The definitions within an arguments block is scoped to the parent node of the arguments element so references to property in an arguments element will reference properties in the argument's parent object. One caveat concerning the arguments element is that you are limited to 10 or less arguments.

The name attribute is used to identify the property name of the current object as it exists within its parent. For example, every movie clip has a Transform instance stored within its transform property. The property name "transform" represents the name that the Transform object would use in XML to associate itself with the transform property of it's parent object. For XML nodes defined in the definition namespace, the name property doesn't also have to be within the same namespace; it can be without a namespace.

The following example creates a Sprite a line drawn in its graphics object and one Shape child object with the instance name "child":

var definition:XML = 
<display:Sprite x="50" y="100"
	xmlns:display="flash.display"
	xmlns:def="com.senocular.xml.XMLDefinition">
	<display:Shape />
	<def:property def:name="graphics">
		<def:call def:name="lineStyle">
			<def:arguments>
				<Number>1</Number>
				<uint>0xFF0000</uint>
			</def:arguments>
		</def:call>
		<def:call name="lineTo">
			<def:arguments>
				<Number>100</Number>
				<Number>100</Number>
			</def:arguments>
		</def:call>
	</def:property>
</display:Sprite>;
var sprite:Sprite = XMLDefinition.parse(definition);
Properties
namespace The namespace used to indicate special nodes (property, call, arguments, name) in the XML definition. Its prefix is "def" and its uri is "com.senocular.xml.XMLDefinition".
Methods
create() Creates a definition XML from a target object. To limit the number of properties that can be returned with the resulting XML, an array of XMLDefinitionFilter instances can be used to determine, by type, which properties are included. The resulting XML object can be used with XMLDefinition.parse to recreate the original object.

Namespaces for the XML returned are automatically named using an incrementing numeric suffix following "ns" for all namespaces except the definition namespace (used for definitions specific to the XMLDefinition class) which instead uses the prefix "def".
parse() Creates an object (typically a display object) based on the definition outlined by the XML. Each XML element represents the object to be made. If that object's definition is in a pacakge, that element will need to be in a namespace whose uri matches that package. The hierarchy of the object created will match the hierarchy of the XML where display objects will be added as children to the display objects. Attributes are used to define properties. If a name attribute is defined, that name will also be used as a property name in the parent to store a reference to the child. If the parent is not a display object container or the child is not a display object and a name attribute is not provided, the child element's index will be used; this is useful when defining arrays as name attributes are not needed.

Errors (most if not all) will fail silently.

Properties

namespace

public static function get namespace():Namespace
The namespace used to indicate special nodes (property, call, arguments, name) in the XML definition. Its prefix is "def" and its uri is "com.senocular.xml.XMLDefinition".

Methods

create()

public static function create(target:Object, xmlParent:XML = null, filters:Array = null, name:String = "", isProperty:Boolean = false):XML
Creates a definition XML from a target object. To limit the number of properties that can be returned with the resulting XML, an array of XMLDefinitionFilter instances can be used to determine, by type, which properties are included. The resulting XML object can be used with XMLDefinition.parse to recreate the original object.

Namespaces for the XML returned are automatically named using an incrementing numeric suffix following "ns" for all namespaces except the definition namespace (used for definitions specific to the XMLDefinition class) which instead uses the prefix "def".
Parameters:
targetThe target object from which a definition XML object is generated.
xmlParentThe XML node in which the resulting XML is inserted.
filtersAn array of XMLDefinitionFilter instances that define the makeup of XML nodes for different types.
nameThe value of the name attribute that defines the property name in the parent object.
isPropertyWhen true, this indicates that the current XML node should be created as a property. This is usually indicated internally based on a filter. If isProperty is true, it is assumed that name is also provided.
Returns:
An XML instance dscribing the target object and its properties and children as a definition XML instance.

parse()

public static function parse(xml:XML, targetParent:Object = null):Object
Creates an object (typically a display object) based on the definition outlined by the XML. Each XML element represents the object to be made. If that object's definition is in a pacakge, that element will need to be in a namespace whose uri matches that package. The hierarchy of the object created will match the hierarchy of the XML where display objects will be added as children to the display objects. Attributes are used to define properties. If a name attribute is defined, that name will also be used as a property name in the parent to store a reference to the child. If the parent is not a display object container or the child is not a display object and a name attribute is not provided, the child element's index will be used; this is useful when defining arrays as name attributes are not needed.

Errors (most if not all) will fail silently.
Parameters:
xmlThe xml to be parsed into an object.
targetParentThe object in which the generated object will be defined, either as a property or a child display object.
Returns:
A reference to the object created.

Page generated: 6:28 am on August 9, 2007