# Having trouble with prototype

**URL:** <https://forum.kirupa.com/t/having-trouble-with-prototype/244491>\
**Category:** flash\
**Created:** [November 19, 2007, 2:23am UTC](https://forum.kirupa.com/t/having-trouble-with-prototype/244491 "2007-11-19T02:23:17Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![girasquid](https://avatars.discourse-cdn.com/v4/letter/g/c57346/32.png) [@girasquid](https://forum.kirupa.com/u/girasquid)\
**Post date:** [November 19, 2007, 2:23am UTC](https://forum.kirupa.com/t/having-trouble-with-prototype/244491/1 "2007-11-19T02:23:17Z")

</div>

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](http://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](http://www.actionscript.org/actionscripts_library/XML_Object/more2.shtml), under the listing “getElementsTagByName”. This is the code:

```auto

// 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:

```auto

**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
