views:

343

answers:

2

Is there a way to change private static field of an alien class?

For example:

package mx.managers {
   public class TooltipManager ... {
        private static var _impl:IToolTipManager2; // <- assign my own value here
        ...
   }
}

In Java it is possible to do it using Reflection API. What about Flex?

+3  A: 

No, that is not possible.

If you are looking into changing the implementation of the TooltipManager, have a look at the Singleton class in the Flex SDK. You'll need to create a custom implementation and register it via the Singleton class before the application initializes. The best is to override the application preloader and do the registration there.

Christophe Herreman
A: 

Well, if you feel like you can handle the extra responsibility, you can monkey patch the class by copying the source into your own source tree with the same package and apply the necessary modifications. That way the flex compiler will use your implementation rather than the SDK implementation.

This technique is sometimes used as a last resort to fix issues which cannot be fixed otherwise. Drawbacks include issues such as forwards compatibility and unintended side effects in the same or other classes dependant on the class your editing.

macke