Referencing an object in an object

Hello,
Could anyone help me. Say I have an object MyObject which has
an XMLSocket defined in it, how I can access the Parent object from the onConnect function:

function MyObject()
{
this.ConnectionState = false;
this.Socket = new XMLSocket();
this.Socket.onConnect = SocketConnect;

}

function SocketConnect()
{
<- Here I want to set ConnectionState to true?
}

Many Thanks,
DumbMonkey.

you can pass the object in as a parameter

function SocketConnect(whichObject)

this._parent should work, I think. Otherwise, you could do something like that:

function MyObject()
{
      this.ConnectionState = false;
      this.Socket = new XMLSocket();
**this.Socket.path = this;**
      this.Socket.onConnect = SocketConnect;
      ....
}

function SocketConnect()
{
this.path.ConnectionState = true;
}

Not sure it will work though :-\

Sen’s idea is probably better (and it has a better chance to work :beam: )

Ilyas’s idea, though, is practical too :slight_smile: just depends on the situation and what you prefer doing.

i think you could use Function.call [size=1]<-- link[/size]

SocketConnect.call(whichObject);

pretty much the same than senocular’s suggestion… :stuck_out_tongue:

Thanks to you all. Much appreciated.
I have tried Illyas idea and it works well (though a little messy).
I would prefer Sens idea, but i cannot override the OnConnect function. This normally passes a bool as a parameter, and I just can’t get it to pass in a reference to the parent class. How would I define it?
Thanks again,
DumbMonkey.

[EDIT] Just worked it out, pretty simple really just define onConnect = SocketConnect(this);

function SocketConnect(Ref) {
Ref.ConnectStatus = true;
}