ggkmath
ggkmath

Reputation: 4246

Flex: how to re-use an existing TitleWindow rather than open another new TitleWindow?

My application has a list of book titles, that when the user clicks on a particular book title, a TitleWindow opens summarizing details about the book. If the user does not close the TitleWindow, but instead selects a different book title, I want the already open TitleWindow to update with the newly selected book title's information. Thus, there only one TitleWindow open at any time for the purpose of viewing more information about any particular book title.

All the spark TitleWindow examples I can find online open a new TitleWindow every time that TitleWindow is used. For example:

http://help.adobe.com/en_US/flex/using/WS6c678f7b363d5da52e8f1ca1124a0430dcf-8000.html

This is what is happening in my case as well. Each time a book title is clicked on a new TitleWindow opens.

Is there any way to re-use an existing TitleWindow if one is already open? Of course, we're not talking about ALL TitleWindows, just a dedicated instance of a TitleWindow used for this purpose.

Currently the variables I'm using inside the TitleWindow are [Bindable] so that the original TitleWindow updates with the relevant information when a new book title is clicked. So, an alternative solution would be to just block new TitleWindows from opening when an existing TitleWindow is already open. So, an alternative solution woudl be to query whether one instance of the TitleWindow is already open, and if so, don't open a new one.

Upvotes: 0

Views: 507

Answers (1)

Barış Uşaklı
Barış Uşaklı

Reputation: 13532

Yes it is possible, just create a title window when the first book is clicked and reuse it on subsequent clicks.

private var _titleWindow:TitleWindow;


private function onBookClicked():void
{
   if(!_titleWindow)
      _titleWindow = PopUpManager.createPopUp(...) as TitleWindow;

   updateTitleWindowWithBookInfo(_titleWindow,bookData);

}

When the user closes the title window instead of removing it just hide it.

Upvotes: 3

Related Questions