View Full Version : XML Data length
Ricmar
June 8th, 2008, 10:48 AM
Wonder if someone can help, I've loaded in to my flash file a bit of text from an external XML document which displays in a text box nicely. What I now need is to be able to get the length of the string. Is this possible?
My initial thought was:
text_box.text = xml;
trace(xml.length());
However the trace box returns the value "1" which is assume is a boolean. Any ideas?
Alex Lexcuk
June 8th, 2008, 11:31 AM
http://dnadillo.dn.ua/fla/XML/img-xml.swf
http://dnadillo.dn.ua/fla/XML/mur_xml_file_img.xml
test text_box.text.length
Ricmar
June 8th, 2008, 11:40 AM
yeah that did it, I actually tried that before but with length() which must have been the problem, thanks Alex
dthought
June 8th, 2008, 12:27 PM
Wouldn't trace(text_box.text.length); work?
You could also use something like xmlTextElement.toString().length if you wanted :)
amarghosh
June 9th, 2008, 05:47 AM
length() always returns 1 for XML objects and number of properties for XMLList objects.
http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/XML.html#length()
use xml.toXMLString().length to get the number of characters;
xml.toString() method works in a little different manner. livedocs says:
toString() method
Returns a string representation of the XML object. The rules for this conversion depend on whether the XML object has simple content or complex content:
* If the XML object has simple content, toString() returns the String contents of the XML object with the following stripped out: the start tag, attributes, namespace declarations, and end tag.
* If the XML object has complex content, toString() returns an XML encoded String representing the entire XML object, including the start tag, attributes, namespace declarations, and end tag.
To return the entire XML object every time, use toXMLString().
dthought
June 9th, 2008, 10:34 AM
Ah yes, thanks for correcting that, amarghosh... still getting a little crossover knowledge from AS2 to AS3... still catches me out from time to time :)
firewalker
June 9th, 2008, 10:43 AM
This is nice feedback, thanks :)
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.