Sure
to sum it up, I am adding the tabbar in main.lua so it will persist, it does everything fine including changing scenes without issue. I am just wanting to be able to call tabBar:pressButton( 1 ) from any lua file that isn’t main.lua and I’m not sure how to do that properly.
main.lua
local storyboard = require "storyboard"
local widget = require "widget"
local function goTo( event )
if event.target.id==1 then
storyboard.gotoScene( "home\_screen" )
elseif event.target.id==2 then
storyboard.gotoScene( "menu1" )
elseif event.target.id==3 then
storyboard.gotoScene( "menu2" )
elseif event.target.id==3 then
storyboard.gotoScene( "documents\_menu" )
else
print("ERROR - unknown tab ID passed to tabBar")
end
end
local tabButtons = {
{ label="Home", up="assets/icons/home\_24.png", down="assets/icons/home\_24\_hi.png", width = 24, height = 24, selected=true, onPress = goTo },
{ label="cobas b 123", up="assets/icons/menu1\_24.png", down="assets/icons/menu1\_24\_hi.png", width = 24, height = 24, onPress = goTo },
{ label="cobas b221", up="assets/icons/menu2\_24.png", down="assets/icons/menu2\_24\_hi.png", width = 24, height = 24, onPress = goTo },
{ label="Documents", up="assets/icons/document\_24.png", down="assets/icons/document\_24\_hi.png", width = 24, height = 24, onPress = goTo },
}
local tabBar = widget.newTabBar{
top = display.contentHeight - 50,
buttons = tabButtons
}
storyboard.gotoScene( "home\_screen" )
What I am hoping to accomplish is that when I click on an image in home_screen, menu1, or menu2 I can update the state of the tabBar to highlight the correct area the user is currently in.
I have tried calling it from within event listeners placed on buttons and just as the other lua enterScene, both of which are giving me the error I mentioned earlier.
for example
in home_screen.lua
function scene:enterScene( event )
tabBar:pressButton( 1 )
end
So I feel like what I am doing is missing some fundamental aspect of targeting tabBar correctly.
[import]uid: 150370 topic_id: 33395 reply_id: 132668[/import]