I am building a hybrid extension that uses flash for the UI. The extension is a modal dialog that has a Ok button, that when pressed, closes the dialog and sends an event to the plugin that makes changes to the current document.
The problem I am running into is that I simply can't get the dialog to close. The plugin is getting the event and the artwork is modified, but the changes don't update (to the screen) until the dialog goes away. I have tried a dozen different ways to close the dialog. It seems that If I dispatch a csxs event before or after a close(), the dialog won't actually close.
One thing I tried was to catch the CSExtension.close event. This is supposed to be called after the extension closes. If I press the Escape key, the dialog closes, this event is fired and I can dispatch my event and everything works correctly. But if I click my Ok button, the dialog doesn't close, and I get the same problem as before.
Here is my okClicked function:
private function okClicked():void
// create the event here
Other things I have tried:
Dispatching a csxs event during any of these will result in the dialog not closing.
I figured out part of the problem.
Our plugin shows a progress bar (AIUser->UpdateProgress()) due to the length of time it takes to modify the artwork. The progress bar is shown before the extension has a chance to close. When this happens, the extension can't close. When I comment out the UpdateProgress code, the artwork is modified and the extension closes just fine.
Another problem now presents itself: when the artwork is modified, nothing shows up for the Undo. I am pushing the AppContext right before the artwork is modified (using the AppContext.hpp/cpp class). I can't prove this yet, but I'm willing to bet that pushing the AppContext doesn't work as long as the extension window is still open.
So, how to close the extension window before the plugin gets the event. That's what I need to figure out.
This still doesn't work. The extension window is still open when the plugin gets the close notification, no matter how I approach it. I think at this point I'm giving up and reworking the dialog to be modeless. It shouldn't take two developers working on this for 4 days to try to figure out how to close a window.
Harbs, thanks for your suggestions.
At least on Mac, when a native dialog is shown on an modal extension window, both window's event handling get stuck.
The workaround I took was to use AITimerSuite.
When you receive an event, do nothing but store the event data and then activate a timer.
After the modal extension is closed, the timer fires and the plugin can do the queued job.
Hope this helps someone who cannot take modeless approach.