PDA

View Full Version : can't find variable



jjfortuin
7 Jan 2011, 4:15 PM
so I have a little bit more info, my application can't find the variable: mainPanel
which is located in my main.js (Ext.setup)

How can I call my mainPanel variable and load it in the Ext.setup so I can access the variable globally?


main.js
Ext.setup({
onReady:function(){

var mainPanel=new Ext.Panel({
id:'Main_Panel',
fullscreen:'true',
layout:'card',
items:[formLogin,tabMenu]
});
}

});

login.js (part of it, this is a handler for a button)
{
text: 'Login',
ui: 'confirm',
handler: function() {mainPanel.setActiveItem(1)},
}

jay@moduscreate.com
11 Jan 2011, 1:03 PM
That's because mainPanel is lexically scoped to the anonymous function that is passed to Ext.onReady.

In this case, try Ext.getCmp('Main_Panel').setActiveItem(1);

jjfortuin
11 Jan 2011, 4:33 PM
Thanks!!! Is there a way to call the mainPanel from Ext.onReady when it's sitting outside of the function and out of Ext.setup?

jay@moduscreate.com
11 Jan 2011, 4:43 PM
no. It's lexically scope to that function.

You should seriously consider using namespaces.

jjfortuin
11 Jan 2011, 5:31 PM
Thanks again, I really appreciate your input. It has been a long time since I "programmed" back in college in Pascal. I'm getting back into the game again, however never used namespaces. I guess I need to buy some good javascript books, there's no Sencha books out yet. Again, Thanks :)