We have reduced support for legacy browsers.

What does this mean for me? You will always be able to play your favorite games on Kongregate. However, certain site features may suddenly stop working and leave you with a severely degraded experience.

What should I do? We strongly urge all our users to upgrade to modern browsers for a better experience and improved security.

Kongregate is a community-driven browser games portal with an open platform for all web games.
Get your games in front of thousands of users while monetizing through ads and virtual goods.
Learn more »

How to refer to 'parent object' of an instance variable?

I have different ‘teamMember’ classes which adds a movieclip portrait, say ‘memberPortrait’.
So teamMember1.memberPortrait, teamMember2.memberPortrait, etc.
I need to add an eventListener to ‘memberPortrait’ which will dynamically call up the teamMember it belongs to, so I can then make that teamMember do something else.
For example…
`
teamMember1.memberPortrait.addEventListener(MouseEvent.CLICK, addToTeam);
public function addToTeam(e:MouseEvent):void
{
var activeTeamMember= e.currentTarget.parent;
stage.addChild(activeTeamMember.memberPortrait2);
}
`
e.currentTarget.parent is the line I’m concerned with… I’m trying to refer to the object that contains the e.currentTarget.

Add the listener within the teamMember class.
Now you dispatch an(other) Event that you can listen for.
This way you do not have to deal with things like parent etc.
Also, don’t ad stuff to the stage.
Just add them to your main class.

Hm I’m not sure how that would solve referencing the parent class from the instance variable.
But I think I found a good solution?
In the teamMember class, I added
memberA.parentMember = this;
So now I can reference the class memberA is in, with memberA.parentMember. It seemed to have worked, so far..

You could have the portrait class have a .member property which points to the member. That gives you instant access. Edit: Which you just did apparently, you ninja!
As long as you’re using it to display the proper portrait, which happens to be referenced on the member, a class that only works as data storage and performs no action, I could see it working. If you want that reference because you want to access the member from that button to make it perform some song-and-dance number that the button really shouldn’t know about, then don’t. Go with Nine’s suggestion instead.

> *Originally posted by **[Levgre](/forums/4/topics/345811?page=1#posts-7198824):***
>
> Hm I’m not sure how that would solve referencing the parent class from the instance variable.
The parent would be dispatching the Event.