<p>If I have a method such as:</p>

<pre><code>private function testMethod(param:string):void
{
  // Get the object that called this function
}
</code></pre>

<p>Inside the testMethod, can I work out what object called us? e.g.</p>

<pre><code>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?
  }
}
</code></pre>

Sorry the answer is no (see edit below).  Functions received a special property called
```
arguments
```
and in AS2 it used to have the property
```
caller
```
that 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:
```
```
var stackTrace:String;

try { throw new Error(); }
catch (e:Error) { stackTrace = e.getStackTrace(); }

var lines:Array = stackTrace.split("\n");
var isDebug:Boolean = (lines[1] as String).indexOf('[') != -1;

var path:String;
var line:int = -1;

if(isDebug)
{
    var regex:RegExp = /at\x20(.+?)\[(.+?)\]/i;
    var matches:Array = regex.exec(lines[2]);

    path = matches[1];

    //file:line = matches[2]
    //windows == 2 because of drive:\
    line = matches[2].split(':')[2];
}
else
{
    path = (lines[2] as String).substring(4);
}

trace(path + (line != -1 ? '[' + line.toString() + ']' : ''));
```
```