views:

266

answers:

1

Hello,

I have a TitleWindow mxml class wich has several components, and listeners. On its creationComplete and init state i add some listeners which listen for events on its gui.

This TitleWindow is only shown when the user click on a "button", i made TitleWindow a singleton with the following code:

public static function getInstance():MyWindow
{
    if ( MyWindow.singleton )
    {
        return MyWindow.singleton;
    }
    else{
        MyWindow.singleton = new MyWindow();
        return MyWindow.singleton;
    }            
}

I needed a singleton because the user will call this window several times as much as he wants and i only need one.

The problem is the following on some special external events i need to "modify" some listeners (remove listeners and add new ones) on a button from MyWindow, before it was even shown once.

I still have MyWindow.getInstance() in memory when my application starts up. However adding /removing listeners does not seem to have any effect if he actual rendering of the components did not happen, event when using the following code on app startup.

  myWindow= MyWindow.getInstance();
  myWindow.initialize();

Not suprisingly if i "show" ('render') the myWindow at least once then the events modifications on the myWindow instance works perfectly.

How can i fake the complete initialisation of this component without showing it on startup ?

Thanks !

+1  A: 

Which sort of a container holds your button? If you are using a Multiple View Container you can try setting the creationPolicy to all. Single View Containers create all their children in one go and you shouldn't face this problem.

From Flex 3.0 docs I could retrieve this:

The default creation policy for all containers, except the Application container, is the policy of the parent container. The default policy for the Application container is auto.

This looks like the cause for all your troubles.

Update: I did not mention this earlier, since I thought this was to be expected :) Setting the creationPolicy to all makes your application load more slowly. So, read up on Ordered Creation -- this technique helps you to choose if the controls are displayed all in one go (which is the default behavior, after all of the controls have been created) or step-by-step, as and when they are created.

dirkgently
You were right, now the problem is that initialising thats particular window on startup takes 2 seconds and hung the system, i wonder if there is an event to know when the rendering is done
coulix
If you went through the documentation you'd already know this :)
dirkgently