View Full Version : After what global values are loaded? Can't access them

1 Sep 2014, 4:36 AM
I understood how to have global values in my extjs application.

Actually i still have some problem while accessing it. It tells me that the value does not exists.
Let me explain with code.

first i have some code of such type:

Myapp.globals = {
selectedTab: -1,
isLoginWindow: false

Then i have a function on every tab that is called "on activate" of such tab.
On loading the first tab is selected, hence it is activated. I try to access to the variable selectedTab with:


It does not work.
But if i erase such code from the first tab and (i.e.) just add on the second tab* , when i will click on the second tab i have access to such value.
On both tabs the function is called "on activate".

*(the second tab is not activated on loading; i have to click on it)

As far as i understood the problem lays on the initialization. In my opinion i should, of course call such function "on activate", but after the initialization has been done.
How could i do that?

Hope that i was enought clear with my description.

4 Sep 2014, 8:09 AM
Where are you defining Myapp.globals?

4 Sep 2014, 11:44 PM
Hi, thanks for the answer.
As you colleague explained here, i added in the launch function (i'm using sencha architect).

Actually this is working, after the application has been fully loaded. I found a solution by defining an external singleton object containing all the variable and requiring my app to require such object, as described here:

by you.
I think that this might be the right solution, or, at least, a good workaround, isn't it? Btw, i haven't yet understood after what event exactly my variables are initialized.:-?

5 Sep 2014, 4:10 AM
Yes, I'm a huge fan of the singleton method as you need to have that class loaded first and then you can use it in any class after that. Having a object defined in the launch method of the application will be after the classes are defined which is too late.

5 Sep 2014, 4:47 AM
I agree with you. actually it seems the best solution. Indeed, just with this solution i'm sure that all the variable are initialized when i need them.