Having trouble with prototype

Hello, all.

I am currently working on a project that involves parsing multiple XML files, and using their attributes. I found a snippet on actionscript.org that would allow me to give Flash’s XML type the “getElementsByTagName” function, but I cannot seem to get the code to work.

The code can be seen here, under the listing “getElementsTagByName”. This is the code:


// special DOM interface "getElementsTagByName" method
// targetName [string]
// returnValue [array / null] : node list
//
// var elements = MyXML.getElementsByTagName("targetName");
// for (var i = 0; i < elements.length; i++) {
//   var item = elements*.firstChild.nodeValue;
// }

XML.prototype.getElementsByTagName = function (targetName) {
        // index of return value
        var index = 0;
        // return value
        var returnValue = new Array();
        
        diverDown(this,targetName);
        
        if (returnValue.length == 0) returnValue = null;
        
        return returnValue;
        
        // local function
        function diverDown(node,targetName) {
                var nodeList = node.childNodes;
                for (var i = 0; i < nodeList.length; i++) {
                        if (nodeList*.nodeType == 1 && nodeList*.hasChildNodes) {
                                if (nodeList*.nodeName == targetName) {
                                        for (var n = 0; n < nodeList*.parentNode.childNodes.length; n++) {
                                                if (nodeList*.parentNode.childNodes[n].nodeName == targetName) {
                                                        returnValue[index] = nodeList*.parentNode.childNodes[n];
                                                        index++;
                                                }
                                        }
                                        return;
                                } else {
                                        diverDown(nodeList*, targetName);
                                }
                        }
                }
                index = 0;
        }
}

However, when I add it to my Flash file, I receive this error:


**Error** Scene=Scene 1, layer=actions, frame=1:Line 20: There is no method with the name 'getElementsTagByName'.
     	trace(countryXML.getElementsTagByName('graphic').length);

Does anyone know what I might be doing wrong in this instance, or what I need to do differently?

Thanks,
Girasquid