View Full Version : Referencing an object in an object
DumbMonkey
June 19th, 2003, 12:13 PM
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.
senocular
June 19th, 2003, 12:22 PM
you can pass the object in as a parameter
function SocketConnect(whichObject)
pom
June 19th, 2003, 12:23 PM
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 :-\
pom
June 19th, 2003, 12:26 PM
Sen's idea is probably better (and it has a better chance to work :beam: )
senocular
June 19th, 2003, 12:36 PM
Ilyas's idea, though, is practical too :) just depends on the situation and what you prefer doing.
kode
June 20th, 2003, 03:40 AM
i think you could use Function.call (http://www.macromedia.com/support/flash/action_scripts/actionscript_dictionary/actionscript_dictionary370.html) <-- link
SocketConnect.call(whichObject);
pretty much the same than senocular's suggestion... :P
DumbMonkey
June 20th, 2003, 03:45 AM
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;
}
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.