arguments.callee._name in ActionScript 2

A question on the flashcoders list about an hour ago triggered me to put together a very simple example that I have been wanting to put together for ages now.

How do you get the name of a function?

With function we could refer to:

  • any function
  • a calling function
  • a function being called

My reflection package is at the core of my xflas2 logger. It provides much the same information MTASC can put into a trace statement WITHOUT MTASC (except for the linenumbers).

Anyway, the reflection package is perfectly capable of being used standalone without a logger of some kind. It provides two simple classes with an even simpler API: ClassFinder and FunctionFinder.

Imagine a function:

	private static function runExample3() {
		_print (
			"I am :"+
			" and I am defined in "+
			" and was called by "+

Note that it’s static, but it doesn’t have to be, I’m just being a lazy git.

This prints:

I am :runExample3 and I am defined in SampleClass and I was called by main

Now, for the small print : you HAVE to call ClassFinder.registerAll() once somewhere at the start of your program.

Download the sample here: [Download not found]

2 replies
  1. Sam Batista
    Sam Batista says:

    Just to let you know friend, I use this occasionally at work when debugging some tricky “who called who from where” issues. Thanks a lot for sharing!

    • Hans Wichman
      Hans Wichman says:

      Hi Sam, thanks man, a postback is always appreciated. I’ve seen your site and I’m guessing you and I both know the time that goes into good software development and blogging:). Ah well time flies when you are having fun:). Don’t know if you are still doing AS2 and if it is of any help, but there is a largely documented full blown as2 logger package here as well, with the whole reflection mumbo jumbo built in. No support whatsoever except the docs and examples already present :):



Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply

Your email address will not be published. Required fields are marked *