PDA

View Full Version : again with highestDepth prototype!



Mona
April 13th, 2005, 07:32 PM
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:



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.



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[i].childNodes[1].firstChild.nodeValue;
}
createTextField(text2, this.highestDepth(), 80, 25*i, 220, 100);
with (eval(text2)) {
text = "text2";
}
}}}



Thank you!

Mona
April 14th, 2005, 01:03 AM
Nevermind!

I found this alternative - and very logical - solution. Doh!



if (globalDepth == null) {
_global.globalDepth = 100000;
_global.setDepth = function() {
return (globalDepth++);
};
}

And then just call the


createTextField(mytext, setDepth(),...

:hugegrin: