# Referencing an object in an object

**URL:** <https://forum.kirupa.com/t/referencing-an-object-in-an-object/23563>\
**Category:** flash\
**Created:** [June 19, 2003, 4:13pm UTC](https://forum.kirupa.com/t/referencing-an-object-in-an-object/23563 "2003-06-19T16:13:49Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![DumbMonkey](https://avatars.discourse-cdn.com/v4/letter/d/a9adbd/32.png) [@DumbMonkey](https://forum.kirupa.com/u/DumbMonkey)\
**Post date:** [June 19, 2003, 4:13pm UTC](https://forum.kirupa.com/t/referencing-an-object-in-an-object/23563/1 "2003-06-19T16:13:49Z")

</div>

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.

---

<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:** [June 19, 2003, 4:22pm UTC](https://forum.kirupa.com/t/referencing-an-object-in-an-object/23563/2 "2003-06-19T16:22:06Z")

</div>

you can pass the object in as a parameter

function SocketConnect(whichObject)

---

<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:** [June 19, 2003, 4:23pm UTC](https://forum.kirupa.com/t/referencing-an-object-in-an-object/23563/3 "2003-06-19T16:23:51Z")

</div>

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

```auto
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 :-\

---

<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:** [June 19, 2003, 4:26pm UTC](https://forum.kirupa.com/t/referencing-an-object-in-an-object/23563/4 "2003-06-19T16:26:23Z")

</div>

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

---

<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:** [June 19, 2003, 4:36pm UTC](https://forum.kirupa.com/t/referencing-an-object-in-an-object/23563/5 "2003-06-19T16:36:52Z")

</div>

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

---

<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:** [June 20, 2003, 7:40am UTC](https://forum.kirupa.com/t/referencing-an-object-in-an-object/23563/6 "2003-06-20T07:40:29Z")

</div>

i think you could use [Function.call](http://www.macromedia.com/support/flash/action_scripts/actionscript_dictionary/actionscript_dictionary370.html) [size=1]\<-- link[/size]

```auto
SocketConnect.call(whichObject);

```

pretty much the same than senocular’s suggestion… 😛

---

<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:** [June 20, 2003, 7:45am UTC](https://forum.kirupa.com/t/referencing-an-object-in-an-object/23563/7 "2003-06-20T07:45:53Z")

</div>

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;  
}
