# Again with highestDepth prototype!

**URL:** <https://forum.kirupa.com/t/again-with-highestdepth-prototype/144394>\
**Category:** Uncategorized\
**Created:** [April 13, 2005, 11:32pm UTC](https://forum.kirupa.com/t/again-with-highestdepth-prototype/144394 "2005-04-13T23:32:32Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mona](https://avatars.discourse-cdn.com/v4/letter/m/ee7513/32.png) [@Mona](https://forum.kirupa.com/u/Mona)\
**Post date:** [April 13, 2005, 11:32pm UTC](https://forum.kirupa.com/t/again-with-highestdepth-prototype/144394/1 "2005-04-13T23:32:32Z")

</div>

I’ve been struggling with this for some time now and I just can’t figure out why one of these scripts works and the other doesn’t. Any help would be great and much needed!

I am creating dynamic text fields from an xml file and I have to publish for player 6, so I can’t use getNextHighestDepth. I have the prototype that can be used instead, but it only works in this first script:

```auto

MovieClip.prototype.highestDepth = function() {
  
	var curr, high = undefined;
	for (var clip in this) {
		if (!isNaN(curr=this[clip].getDepth()) && this[clip]._parent == this) {
			if (curr>high || high == undefined) {
				high = curr;
			}
		}
	}
	return high+1;
};

for (var i = 0; i<10; i++) {
	mytext1 = " mytext1 "+i;
	mytext2 = " mytext2 "+i;
	createTextField(mytext1, this.highestDepth(), 0, i*20, 220, 100);
	trace(this.highestDepth());
	with (eval(mytext1)) {
		text = "text1";
	}
	createTextField(mytext2, this.highestDepth(), 50, i*20, 220, 100);
	with (eval(mytext2)) {
		text = "text2";
	}
}

```

However when I use it like this, it doesn’t even seem to call the prototype.

```auto
 
MovieClip.prototype.highestDepth = function() {
   
	var curr, high = undefined;
	for (var clip in this) {
		if (!isNaN(curr=this[clip].getDepth()) && this[clip]._parent == this) {
			if (curr>high || high == undefined) {
				high = curr;
			}
		}
	}
	return high+1;
};

xmlData = new XML();
xmlData.ignoreWhite = true;
xmlData.onLoad = loadXML;
xmlData.load("myFile.xml");

function loadXML(loaded) {
	if (loaded) {
		myXML = this.firstChild.childNodes;
		for (var i = 0; i<myXML.length; i++) {
			text1 = "text1"+i;
			text2 = "text2"+i;
			createTextField(text1, this.highestDepth(), 0, 20*i, 220, 100);
			with (eval(text1)) {
			   text = this.firstChild.childNodes*.childNodes[1].firstChild.nodeValue;
			}
			createTextField(text2, this.highestDepth(), 80, 25*i, 220, 100);
			with (eval(text2)) {
				text = "text2";
			}
}}}

```

Thank you!
