Search code examples
apache-flexeventsparsley

How to determine which class has called a function


I am working on a Flex Front End at the moment, and have been using the Parsley framework for passing messages/events around.

I was wondering if there is a simple way for a function (in this case, an event's constructor) to obtain a reference to the object which called it?

This is to ensure that a certain event that I am defining can only be dispatched by one specified class. My thinking is to check the caller of the constructor somehow, and throw an error if it is not of the correct type.

I am open to suggestions of alternative approaches here, but I would ideally like to stick to using the Parsley 'MessageHandler' approach if at all possible.

Thanks for reading guys..


Solution

  • Stack trace works, but you could much more easily pass a reference to the caller to the function and type check it.

    function dispatchEvent(caller:*):void {
       if(caller is SpecificClass) {
          // then dispatch event
       }
    }