I have been confronted lately with some important limitations of the Captivate Widget Framework. It seems that Captivate loads the widget’s swf into its own Applicationdomain. An Applicationdomain is basically a container for discrete groups of Class and classes in different ApplicationDomains cannot communicate together. This segregation can sometimes be a good thing but for widget developers, it is a very bad thing!
For one, it prevents us from using Static variables. In one of my widget, I had some plans to have many instances of the widget share a common component. So, I created a Static variable that was supposed to contain the shared component. To my surprise, it looked like the component I modified in one instance of the widget was never available in another instance. It took me a while to realize that the widgets were on their own Applicationdomain.
So, I decided to try to go around this by dynamically attaching the shared component to the CaptivateMainTimeline movieclip. That worked OK until I tried to cast the shared component into its proper type. The debugger welcomed me with an error message saying that the cast was invalid. This is another side effect of having different Applicationdomains. For the Plash Player, when the exact same class definition is loaded into two different Applicationdomains, it is as if it was two different classes; just like if I was to compare an apple with an orange.
Ok, that sucks! I finally was able to do it by casting the shared component into an Object. This way, the compiler ignores the errors. The drawbacks of this is that I lose the capability to use strongly typed variables and I also lose the auto-completion in my IDE. Not a nice tradeoff at all!
So, for those of you would want to share a common component between widget instances, you will have to attach the shared component to the CaptivateMainTimeline and access it through an Object type. The only other solution that I can see is to try to use the EventDispatcher provided by the widget framework to communicate changes.
If Adobe’s developers are reading this, it would be nice to understand why this was done. I would really like the next version of Captivate to load the widgets in the core Applicationdomain so we can start doing powerful stuff.