Hi Simone,

your code fails because when you destroy the Window, it destroys its 
children, including the ColorSelector. Then on the second button press, 
you're trying to add the disposed selector to the new Window which 
causes the exception. So a quick fix would be to move the ColorSelector 
instantiation into the "execute" listener callback function.

However, that would still create a new Window every time the button is 
clicked, which is not what you want (and would be a bad idea since 
creating objects is expensive). Instead, you could implement the 
Singleton pattern. Your button listener would just look like this:

       button1.addListener("execute", function(e) {
         this._getWindow().open();
       }, this);

While _getWindow would be a new method that makes sure only one instance 
is created:

     _getWindow : function()
     {
       if (!this.__window) {
         var selector = new qx.ui.control.ColorSelector();
         var window = this.__window = new qx.ui.window.Window();
         window.setModal(true);
         window.setLayout(new qx.ui.layout.Basic() );
         window.add(selector);
       }
       return this.__window;
     }


Regards,
Daniel

On 07/05/2011 01:44 PM, Simone Pandolfo wrote:
> Hi all,
>
> i'm trying to have one signle istance of an object, i write a short
> example:
> http://tinyurl.com/67fx8hs
>
> inside a button listener i create an window object and add to it a
> listener "beforeClose" to destroy it, but at the next "execute" of the
> button the window don't be create again and throw an error.
>
> Uncaught TypeError: Cannot read property '__fn' of null
>
> I need this because i want hide all the other window, and after show
> again, but if i don't destroy the object i see the window twice, the old
> istance and the new one.
>
> what i wrong?
>
> Best Regards
>   Sp
>

------------------------------------------------------------------------------
All of the data generated in your IT infrastructure is seriously valuable.
Why? It contains a definitive record of application performance, security 
threats, fraudulent activity, and more. Splunk takes this data and makes 
sense of it. IT sense. And common sense.
http://p.sf.net/sfu/splunk-d2d-c2
_______________________________________________
qooxdoo-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel

Reply via email to