开发者

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 framewor开发者_Go百科k 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..


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
   }
}


Disclaimer: I'm not familiar with Parsley.

See stack trace in actionscript 3. You can get the caller function from the stack trace.

There is one thing though.. The stack trace can only be detected in debug mode and to my knowledge there is no way to get the caller in "production" mode.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜