# This. reference within and object

**URL:** <https://forum.kirupa.com/t/this-reference-within-and-object/1826>\
**Category:** Uncategorized\
**Created:** [May 16, 2002, 6:10pm UTC](https://forum.kirupa.com/t/this-reference-within-and-object/1826 "2002-05-16T18:10:57Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [May 16, 2002, 6:10pm UTC](https://forum.kirupa.com/t/this-reference-within-and-object/1826/1 "2002-05-16T18:10:57Z")

</div>

I am trying to make a module to load and parse some xml and have run into some problems so I made this sample code to work with it. The code works fine if I have a reference (see the line with \*\*\*\*\*\*\*\*\*\*\*\*\*\*) the setVariables method with the name jObject.setVariables, but when I use: this.setVariables :it doesn’t work. When I use: trace(this); : it prints the whole XML document. Any Ideas?

myTry = function(myObjName){  
this.name = myObjName;  
trace(“myTry object made”);  
}  
myTry.prototype.name;  
myTry.prototype.myXMLDoc;  
myTry.prototype.eventNum = null;  
myTry.prototype.eventTitles = new Array();  
myTry.prototype.eventDescriptions = new Array();  
myTry.prototype.eventReferences = new Array();  
myTry.prototype.myLoadEm = function(success){  
if(!success ){  
trace(“Your document didn’t load”);

}else{  
trace(“Your document loaded”);  
trace("::::::::::::::::::::::\<img src=http://www.ezboard.com/intl/aenglish/images/emoticons/ohwell.gif ALT=":"\> n" +this + "  
");  
\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\* this.setVariables(); \*\*\*\*\*\*\*\*\*\*\*\*\*  
//trace(myXMLDoc);  
}  
}

myTry.prototype.makeIt = function(){  
myXMLDoc = new XML();  
myXMLDoc.load(“T1.xml”);  
myXMLDoc.ignoreWhite = true;  
myXMLDoc.onLoad = this.myLoadEm;  
}

myTry.prototype.setVariables = function (){  
trace(“In the setVariables”);  
this.eventNum = myXMLDoc.firstChild.childNodes.length;

for(i=0;i this.eventTitles = myXMLDoc.firstChild.childNodes.attributes.title;  
this.eventDescriptions = myXMLDoc.firstChild.childNodes.firstChild.firstChild.firstChild;  
this.eventReferences = new Array();[//XMLData.firstChild.childNodes.firstChild.childNodes](https://XMLData.firstChild.childNodes.firstChild.childNodes);//.nextSibling.firstChild;  
this.eventNum = myXMLDoc.firstChild.childNodes.firstChild;  
for(j=0;j.firstChild.firstChild.nextSibling.childNodes.length; j++){  
this.eventReferences[j] = myXMLDoc.firstChild.childNodes.firstChild.firstChild.nextSibling.childNodes[j].firstChild;  
}  
trace(this.eventReferences);  
}  
return 1;  
}

jObject = new myTry(jObject);  
jObject.makeIt();  
trace(jObject.name);  
obj2 = new myTry(“blamb!!!”);  
trace(obj2.name);
