I am currently experimenting with a TabGroup feature in my application, but I encountered an issue when trying to utilize the setActiveTab function from a separate JavaScript file.
The problem arises specifically when attempting to click button3 located within the third tab. An error message stating "tabGroup is not defined" is displayed.
The following code snippet is from app.js:
var tabGroup = Titanium.UI.createTabGroup()
var window1 = Titanium.UI.createWindow({
backgroundColor: 'cyan'
})
var window2 = Titanium.UI.createWindow({
backgroundColor: 'magenta'
})
var window3 = Titanium.UI.createWindow({
backgroundColor: 'yellow',
url: 'thirdTab.js'
})
var tab1 = Titanium.UI.createTab({
title: 'First tab',
window: window1
})
var tab2 = Titanium.UI.createTab({
title: 'Second tab',
window: window2
})
var tab3 = Titanium.UI.createTab({
title: 'Third tab',
window: window3
})
tabGroup.addTab(tab1)
tabGroup.addTab(tab2)
tabGroup.addTab(tab3)
tabGroup.open()
var button1 = Titanium.UI.createButton({
title: 'go to second',
widgh: Titanium.UI.SIZE,
height: Titanium.UI.SIZE
})
button1.addEventListener('click', function(e){
tabGroup.setActiveTab(1);
})
var button2 = Titanium.UI.createButton({
title: 'go to third',
widgh: Titanium.UI.SIZE,
height: Titanium.UI.SIZE
})
button2.addEventListener('click', function(e){
tabGroup.setActiveTab(2);
})
window1.add(button1)
window2.add(button2)
This piece of code belongs to the thirdTab.js file:
var window3 = Titanium.UI.currentWindow
var button3 = Titanium.UI.createButton({
title: 'go to first',
widgh: Titanium.UI.SIZE,
height: Titanium.UI.SIZE
})
window3.add(button3)
button3.addEventListener('click', function(e){
tabGroup.setActiveTab(0);
})