If I have a method such as:
private function testMethod(param:string):void { // Get the object that called this function }
Inside the testMethod, can I work out what object called us? e.g.
class A { doSomething() { var b:B = new B(); b.fooBar(); } } class B { fooBar() { // Can I tell that the calling object is type of class A? } }
Sorry the answer is no (see edit below). Functions received a special property called
argumentsand in AS2 it used to have the propertycallerthat would do roughly what you want. Although the arguments object is still available in AS3 the caller property was removed from AS3 (and therefore Flex 3) so there is no direct way you can do what you want. It is also recommeded that you use the […rest parameter](http://livedocs.adobe.com/flex/3/langref/statements.html#…_(rest)_parameter) language feature instead of arguments.Here is a reference on the matter (search for callee to find the relevant details).
Edit: Further investigation has shown that it is possible to get a stack trace for the current executing function so if you are lucky you can do something with that. See this blog entry and this forum post for more details.
The basic idea from the blog post is you throw an Error and then catch it immediately and then parse the stack trace. Ugly, but it may work for you.
code from the blog post: