Reputation: 1541
What can be the way to know the class name "Abc" from where the function of a reference variable "def" has been called ? Except these two ways :
1) Adding the def as a child of Abc
2) Injecting reference of Abc into Def prior or during the function call.
here is the class Abc :
public class Abc
{
var def:Def ;
public function Abc()
{
def = new Def();
def.myfun() ;
}
}
public class Def
{
public function Def()
{
}
public function myfun():void
{
// Code to know, this function has been called from class named Abc ;
}
}
Upvotes: 0
Views: 53
Reputation: 39458
No, that is not possible. It is also useless. The closest thing you can do to what you want is to get a reference to the function calling Abc.myfun()
via arguments.callee
:
public function myfun():void
{
var callee:Function = arguments.callee;
}
Though this won't have any useful information attached like the function or class name.
Upvotes: 1
Reputation: 153
You could get the information from the stacktrace, but that would only work in debug mode.
There isn't really a clean way to do it, because you shouldn't need to do it. If you explained a bit more about your situation / goal there is probably a simple answer (requiring a small redesign) that will help you. (cant post comments)
Upvotes: 0
Reputation: 981
Maybe like this:
public class Abc
{
var def:Def;
public function Abc()
{
def = new Def();
def.myfun( true ) ;
}
}
public class Def
{
public function Def()
{
}
public function myfun(fromAbc:Boolean=false):void
{
if( fromAbc == true )
{
// Code to know, this function has been called from class named Abc ;
}
}
}
Upvotes: 0