flash

Page 102

Chapter 4

Using XML Data in Flash

Just as in the toHTML() method, you use HTML to format the text, in this case attributes, to not only be rendered to screen but also colored differently. First the element nodeName is colored yellow, and then the attributes are colored light blue. The final piece of this function displays the nodeValue of the node if it is not the element node detected in the if statement, and then displays the number of childNodes before adding the formatted bottom line divider: else { outString += “<br /><b>string: </b>”+ this.nodeValue; } outString += “<br /><b>Number of childNodes: </b>”; outString += this.childnodes.length; outString += “<br /><u><pre> </pre></u>”; return(outString);

The last line is where this information is returned for display. Once it’s complete, this entire string representation, formatted in HTML and contained in outString, is placed into the output text field in the msgViewer movieClip. There is one other interactive way to present information in this example. If you roll over the question mark button at the window’s top left, you trigger an action on another transparent button that calls the function show_doc_details: function show_doc_details() { function tagKiller(str) { /* This function rips the brackets off an xmlDecl or a docTypeDecl, so they can be added as < and > later, for proper output. */ str = substring(str,2,(str.length-2)); // take the first and last characters off the string return(str); } _root.msgViewer.output = “Status: “+_root.linkdata.status+”\n”; _root.msgViewer.output += _root.linkdata.xmlDecl + “\n”; _root.msgViewer.output += _root.linkdata.docTypeDecl; if (_root.linkdata.xmlDecl != null) { //if there is an xmlDecl... _root.msgViewer.output += “<font color=’#00ee00’><”; _root.msgViewer.output += tagKiller(_root.linkdata.xmlDecl); _root.msgViewer.output += “></font><br />”; } if (_root.linkdata.docTypeDecl != null) { //if there is an xmlDecl... _root.msgViewer.output += “<font color=’#00ee00’><”; _root.msgViewer.output += tagKiller(_root.linkdata.docTypeDecl) _root.msgViewer.output += “></font>+<br />”; } }

89


Issuu converts static files into: digital portfolios, online yearbooks, online catalogs, digital photo albums and more. Sign up and create your flipbook.