Tutorials, extensions, and source files for ActionScript, Flash, and other Adobe products.

 

senocular.com ActionScript Library

text.as

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
// adds a text property that represents the text (nodeValue)
// of a text node. This can be called from a text node *or* an
// element which contains a text node (retrieves the last child)
// making it easy to access text from an element which only
// contains one text node
XMLNode.prototype.text = function(){
	var n = this;
	if (n.nodeType == 1) n = this.lastChild;
	return n;
}
XMLNode.prototype.addProperty("text",
	function(){
		var n = this.text();
		if (n.nodeType == 3) return n.nodeValue;
		return "";
	},
	function(txt){
		var n = this.text();
		if (n.nodeType == 3) n.nodeValue = txt;
		else this.appendChild(new XML().createTextNode(txt));
	}
);