Skip to main content
Participant
October 21, 2010
Question

how to get the reference of one object's parent

  • October 21, 2010
  • 2 replies
  • 368 views

hello guys

i have classA and classB like bellow

class ClassA{

public var myVar:String="test";

public function ClassA()

{

new ClassB();

}

}

class ClassB{

public function ClassB()

{

trace("my parent is"+XXX);

trace("my parent var is"+ XXX["myVar"]);

}

}

suppose XXX in classB is the reference of instance of ClassA.how do i get it?

This topic has been closed for replies.

2 replies

Inspiring
October 21, 2010

Parent/child relationships pertain to display list only. When you instantiate ClassB in ClassA - it becomes a property of the scope where you instantiated it - NOT A CHILD. Note the word "scope" - variable may belong to class or function, etc.

Instance of a class is totally agnostic to who instantiated it unless you pass a reference of the class that made the instance. Nevertheless, of a class is a DisplayObject, once it is placed on display list - it knows who the parent is.

Instance can be either property or child or both proeprty and child.

October 21, 2010

class ClassB{

public function ClassB()

{

var classa:ClassA=new ClassA();

trace("my parent is"+classa.myVar.);

}

}

should work