Deselecting tab button when entering another scene .ANSWER ASAP PLEASE

i have some work to hand in and so i need urgent help

i am trying to make the tab button on the tab bar at the bottom of my app deselect when i enter into another scene that is attached to a button on the scen attached to the tab button.

at the moment the tab button stays pressed down and so if i try to go back to the scene linked to the tab bar it wont work as the tab button is already pressed down

(just to make things easier to understand i’ll put a flow diagram below to show which scene links to which button)

TabButton1>(linked to)>scene1>button (within scene1)>linked to scene2

thanks

also another problem i am having is that,

i have a scene in which if i click a button an object transitions from one place to another however if the transition is incomplete and i switch to a different scene via the tab bar button and then go back onto the same scene i was in before the transition is still on going

ive tried all the different:

storyboard.purgeScene()
storyboard.removeAll()

storyboard.purgeAll()

etc

non seem to be working

I NEED HELP BEFORE 10PM GMT PLEASE thankyou to who ever helps :slight_smile:

If scene2 is also a tabBar selectable scene, you can use the setSelected() method to change the tabBar button to scene 2.  See:  http://docs.coronalabs.com/api/type/TabBarWidget/setSelected.html

However, if scene2 isn’t a selectable scene from the tabBar, then it’s correct to keep the tab selected as from the tabBar perspective you are still on scene 1.

Make sense?

As for the transition, it’s not something that’s included in the display hierarchy.  What you are transitioning is included, but the transition itself is not.  You’re lucky that removing the scene doesn’t crash the app.  You should make sure to cancel any transitions in the scene’s exitScene() function.

thanks for the help, im having problem setting the transitions as variables

there are alot of transitions linked to an event which is linked to a button

i tried to set them as variables of both the same name and of different names but the transition.cancel() function doesnt seem to be working

here is the code

leftEyeMovement = 1 local function event3(event) if leftEyeMovement == 1 then local function finishMove1() button3:setLabel("Please Press To Reset") leftEyeMovement = 2 end leftEyeMovement = 3 button:setEnabled(false) button2:setEnabled(false) transition.to(eye2, { time = 1000, x = 30, delta = true, transition = easing.outQuad }) transition.to(leftEyeCover, { time = 1000, x = 325, delta = true, transition = easing.outQuad }) transition.to(leftEyeCover, { time = 1000, delay = 2000, x = 500, delta = true, transition = easing.outQuad }) transition.to(eye2, { time = 1000, delay = 2000, x = -30, delta = true, transition = easing.outQuad }) transition.to(eye, { time = 1000, delay = 2000, x = 30, delta = true, transition = easing.outQuad }) transition.to(leftEyeCover, { time = 1000, delay = 4000, x = -500, delta = true, transition = easing.outQuad }) transition.to(eye2, { time = 1000, delay = 4000, x = 30, delta = true, transition = easing.outQuad }) transition.to(eye, { time = 1000, delay = 4000, x = -30, delta = true, transition = easing.outQuad }) transition.to(leftEyeCover, { time = 1000, delay = 6000, x = 500, delta = true, transition = easing.outQuad }) transition.to(eye2, { time = 1000, x = -30,delay = 6000, delta = true, transition = easing.outQuad }) transition.to(eye, { time = 1000, x = 30,delay = 6000, delta = true, transition = easing.outQuad, onComplete = finishMove1 }) end if leftEyeMovement == 2 then local function finishMove2() button:setEnabled(true) button2:setEnabled(true) leftEyeMovement = 1 end leftEyeMovement = 3 transition.to(leftEyeCover, { time = 1000, x = -825, delta = true, transition = easing.outQuad }) transition.to(eye, { time = 1000, x = -30, delta = true, transition = easing.outQuad, onComplete = finishMove2 }) button3:setLabel("Alternate Test") end end

Hi @dcj_786,

Are you trying to cancel all transitions at once, or by variable? I don’t see this part in your code… please post a bit more.

Thanks,

Brent

What i tried to do was, before every ‘transition.to’ i put ‘local transitionObject1 =’
With the number at the end changing for each one of the transitions e.g ‘local transitionObject2 =’
And then i put ‘transition.cancel( transitionObject1 )’ , in the ‘exitScene( )’ function
I did this for each of the transitions and found that it didnt work so i removed them bits of code hence it isnt present above

My aim to to cancel all the transitions

Thanks :slight_smile:

I would recommend using a table:

local myTransitions = {}

When you do each transitions:

myTransitions[#myTransitions + 1] = transition.to(eye2, { time = 1000, x = 30, delta = true, transition = easing.outQuad })

Then when you’re done:

for i = #myTransitions, 1, -1 do

     if myTransitions[i] then

          transition.cancel(myTransitions[i])

          myTransitions[i] = nil

     end

end

Of course the myTransitions table needs to be scoped so that its visible where you are creating the transitions as well as the exitScene() function.

hi

sory for the late reply ive been caught up recently.

i tried what you  said above but without luck

im probably doing it worng can you help me please?

local myTransitions = {} leftEyeMovement = 1 local function event3(event) if leftEyeMovement == 1 then local function finishMove1() button3:setLabel("Please Press To Reset") leftEyeMovement = 2 end leftEyeMovement = 3 button:setEnabled(false) button2:setEnabled(false) myTransitions[#myTransitions + 1] = transition.to(eye2, { time = 1000, x = 30, delta = true, transition = easing.outQuad }) myTransitions[#myTransitions + 1] = transition.to(leftEyeCover, { time = 1000, x = 325, delta = true, transition = easing.outQuad }) myTransitions[#myTransitions + 1] = transition.to(leftEyeCover, { time = 1000, delay = 2000, x = 500, delta = true, transition = easing.outQuad }) myTransitions[#myTransitions + 1] = transition.to(eye2, { time = 1000, delay = 2000, x = -30, delta = true, transition = easing.outQuad }) myTransitions[#myTransitions + 1] = transition.to(eye, { time = 1000, delay = 2000, x = 30, delta = true, transition = easing.outQuad }) myTransitions[#myTransitions + 1] = transition.to(leftEyeCover, { time = 1000, delay = 4000, x = -500, delta = true, transition = easing.outQuad }) myTransitions[#myTransitions + 1] = transition.to(eye2, { time = 1000, delay = 4000, x = 30, delta = true, transition = easing.outQuad }) myTransitions[#myTransitions + 1] = transition.to(eye, { time = 1000, delay = 4000, x = -30, delta = true, transition = easing.outQuad }) myTransitions[#myTransitions + 1] = transition.to(leftEyeCover, { time = 1000, delay = 6000, x = 500, delta = true, transition = easing.outQuad }) myTransitions[#myTransitions + 1] = transition.to(eye2, { time = 1000, x = -30,delay = 6000, delta = true, transition = easing.outQuad }) myTransitions[#myTransitions + 1] = transition.to(eye, { time = 1000, x = 30,delay = 6000, delta = true, transition = easing.outQuad, onComplete = finishMove1 }) end if leftEyeMovement == 2 then local function finishMove2() button:setEnabled(true) button2:setEnabled(true) leftEyeMovement = 1 end leftEyeMovement = 3 myTransitions[#myTransitions + 1] = transition.to(leftEyeCover, { time = 1000, x = -825, delta = true, transition = easing.outQuad }) myTransitions[#myTransitions + 1] = transition.to(eye, { time = 1000, x = -30, delta = true, transition = easing.outQuad, onComplete = finishMove2 }) button3:setLabel("Alternate Test") end end button3 = widget.newButton{ label = "Alternating Test", fontSize = 30, width = 640, height = 90, left = 0, top = 750, onRelease = event3 } function scene:exitScene( event ) for i = #myTransitions, 1, -1 do if myTransitions[i] then transition.cancel(myTransitions[i]) myTransitions[i] = nil end end

thanks

maybe try this:

for i = table.maxn(myTransitions), 1, -1 do     if myTransitions[i] then         transition.cancel(myTransitions[i])         myTransitions[i] = nil     end end

It’s possible that your transitions when they end are setting themselves to nil and that’s breaking how #tablename works.  It doesn’t like nil’s in the middle of the table.

Rob

also another problem i am having is that,

i have a scene in which if i click a button an object transitions from one place to another however if the transition is incomplete and i switch to a different scene via the tab bar button and then go back onto the same scene i was in before the transition is still on going

ive tried all the different:

storyboard.purgeScene()
storyboard.removeAll()

storyboard.purgeAll()

etc

non seem to be working

I NEED HELP BEFORE 10PM GMT PLEASE thankyou to who ever helps :slight_smile:

If scene2 is also a tabBar selectable scene, you can use the setSelected() method to change the tabBar button to scene 2.  See:  http://docs.coronalabs.com/api/type/TabBarWidget/setSelected.html

However, if scene2 isn’t a selectable scene from the tabBar, then it’s correct to keep the tab selected as from the tabBar perspective you are still on scene 1.

Make sense?

As for the transition, it’s not something that’s included in the display hierarchy.  What you are transitioning is included, but the transition itself is not.  You’re lucky that removing the scene doesn’t crash the app.  You should make sure to cancel any transitions in the scene’s exitScene() function.

thanks for the help, im having problem setting the transitions as variables

there are alot of transitions linked to an event which is linked to a button

i tried to set them as variables of both the same name and of different names but the transition.cancel() function doesnt seem to be working

here is the code

leftEyeMovement = 1 local function event3(event) if leftEyeMovement == 1 then local function finishMove1() button3:setLabel("Please Press To Reset") leftEyeMovement = 2 end leftEyeMovement = 3 button:setEnabled(false) button2:setEnabled(false) transition.to(eye2, { time = 1000, x = 30, delta = true, transition = easing.outQuad }) transition.to(leftEyeCover, { time = 1000, x = 325, delta = true, transition = easing.outQuad }) transition.to(leftEyeCover, { time = 1000, delay = 2000, x = 500, delta = true, transition = easing.outQuad }) transition.to(eye2, { time = 1000, delay = 2000, x = -30, delta = true, transition = easing.outQuad }) transition.to(eye, { time = 1000, delay = 2000, x = 30, delta = true, transition = easing.outQuad }) transition.to(leftEyeCover, { time = 1000, delay = 4000, x = -500, delta = true, transition = easing.outQuad }) transition.to(eye2, { time = 1000, delay = 4000, x = 30, delta = true, transition = easing.outQuad }) transition.to(eye, { time = 1000, delay = 4000, x = -30, delta = true, transition = easing.outQuad }) transition.to(leftEyeCover, { time = 1000, delay = 6000, x = 500, delta = true, transition = easing.outQuad }) transition.to(eye2, { time = 1000, x = -30,delay = 6000, delta = true, transition = easing.outQuad }) transition.to(eye, { time = 1000, x = 30,delay = 6000, delta = true, transition = easing.outQuad, onComplete = finishMove1 }) end if leftEyeMovement == 2 then local function finishMove2() button:setEnabled(true) button2:setEnabled(true) leftEyeMovement = 1 end leftEyeMovement = 3 transition.to(leftEyeCover, { time = 1000, x = -825, delta = true, transition = easing.outQuad }) transition.to(eye, { time = 1000, x = -30, delta = true, transition = easing.outQuad, onComplete = finishMove2 }) button3:setLabel("Alternate Test") end end

Hi @dcj_786,

Are you trying to cancel all transitions at once, or by variable? I don’t see this part in your code… please post a bit more.

Thanks,

Brent

What i tried to do was, before every ‘transition.to’ i put ‘local transitionObject1 =’
With the number at the end changing for each one of the transitions e.g ‘local transitionObject2 =’
And then i put ‘transition.cancel( transitionObject1 )’ , in the ‘exitScene( )’ function
I did this for each of the transitions and found that it didnt work so i removed them bits of code hence it isnt present above

My aim to to cancel all the transitions

Thanks :slight_smile:

I would recommend using a table:

local myTransitions = {}

When you do each transitions:

myTransitions[#myTransitions + 1] = transition.to(eye2, { time = 1000, x = 30, delta = true, transition = easing.outQuad })

Then when you’re done:

for i = #myTransitions, 1, -1 do

     if myTransitions[i] then

          transition.cancel(myTransitions[i])

          myTransitions[i] = nil

     end

end

Of course the myTransitions table needs to be scoped so that its visible where you are creating the transitions as well as the exitScene() function.

hi

sory for the late reply ive been caught up recently.

i tried what you  said above but without luck

im probably doing it worng can you help me please?

local myTransitions = {} leftEyeMovement = 1 local function event3(event) if leftEyeMovement == 1 then local function finishMove1() button3:setLabel("Please Press To Reset") leftEyeMovement = 2 end leftEyeMovement = 3 button:setEnabled(false) button2:setEnabled(false) myTransitions[#myTransitions + 1] = transition.to(eye2, { time = 1000, x = 30, delta = true, transition = easing.outQuad }) myTransitions[#myTransitions + 1] = transition.to(leftEyeCover, { time = 1000, x = 325, delta = true, transition = easing.outQuad }) myTransitions[#myTransitions + 1] = transition.to(leftEyeCover, { time = 1000, delay = 2000, x = 500, delta = true, transition = easing.outQuad }) myTransitions[#myTransitions + 1] = transition.to(eye2, { time = 1000, delay = 2000, x = -30, delta = true, transition = easing.outQuad }) myTransitions[#myTransitions + 1] = transition.to(eye, { time = 1000, delay = 2000, x = 30, delta = true, transition = easing.outQuad }) myTransitions[#myTransitions + 1] = transition.to(leftEyeCover, { time = 1000, delay = 4000, x = -500, delta = true, transition = easing.outQuad }) myTransitions[#myTransitions + 1] = transition.to(eye2, { time = 1000, delay = 4000, x = 30, delta = true, transition = easing.outQuad }) myTransitions[#myTransitions + 1] = transition.to(eye, { time = 1000, delay = 4000, x = -30, delta = true, transition = easing.outQuad }) myTransitions[#myTransitions + 1] = transition.to(leftEyeCover, { time = 1000, delay = 6000, x = 500, delta = true, transition = easing.outQuad }) myTransitions[#myTransitions + 1] = transition.to(eye2, { time = 1000, x = -30,delay = 6000, delta = true, transition = easing.outQuad }) myTransitions[#myTransitions + 1] = transition.to(eye, { time = 1000, x = 30,delay = 6000, delta = true, transition = easing.outQuad, onComplete = finishMove1 }) end if leftEyeMovement == 2 then local function finishMove2() button:setEnabled(true) button2:setEnabled(true) leftEyeMovement = 1 end leftEyeMovement = 3 myTransitions[#myTransitions + 1] = transition.to(leftEyeCover, { time = 1000, x = -825, delta = true, transition = easing.outQuad }) myTransitions[#myTransitions + 1] = transition.to(eye, { time = 1000, x = -30, delta = true, transition = easing.outQuad, onComplete = finishMove2 }) button3:setLabel("Alternate Test") end end button3 = widget.newButton{ label = "Alternating Test", fontSize = 30, width = 640, height = 90, left = 0, top = 750, onRelease = event3 } function scene:exitScene( event ) for i = #myTransitions, 1, -1 do if myTransitions[i] then transition.cancel(myTransitions[i]) myTransitions[i] = nil end end

thanks

maybe try this:

for i = table.maxn(myTransitions), 1, -1 do     if myTransitions[i] then         transition.cancel(myTransitions[i])         myTransitions[i] = nil     end end

It’s possible that your transitions when they end are setting themselves to nil and that’s breaking how #tablename works.  It doesn’t like nil’s in the middle of the table.

Rob

Any other way around this problem? (sorry for the late responses)

I’m sure you could work something else out, but I can’t thing of a better way.  The only difference is making sure to use table.maxn(tablename) instead of #tablename.  Pretty straight forward.

Rob

i tried what you said above but when i go out of the scene and into another menu and then back into that scene the image doesnt reset its self. i dont have a clue whats gone wrong/ what i need to do.

thanks for your help so far, if i can get past this problem then ive completed my app.

if anyone knows how i could fix my code please help thankyou

------function attached to button3 local myTransitions = {} leftEyeMovement = 1 local function event3(event) if leftEyeMovement == 1 then local function finishMove1() button3:setLabel("Please Press To Reset") leftEyeMovement = 2 end leftEyeMovement = 3 button:setEnabled(false) button2:setEnabled(false) myTransitions[#myTransitions + 1] = transition.to(eye2, { time = 1000, x = 30, delta = true, transition = easing.outQuad }) myTransitions[#myTransitions + 1] = transition.to(leftEyeCover, { time = 1000, x = 325, delta = true, transition = easing.outQuad }) myTransitions[#myTransitions + 1] = transition.to(leftEyeCover, { time = 1000, delay = 2000, x = 500, delta = true, transition = easing.outQuad }) myTransitions[#myTransitions + 1] = transition.to(eye2, { time = 1000, delay = 2000, x = -30, delta = true, transition = easing.outQuad }) myTransitions[#myTransitions + 1] = transition.to(eye, { time = 1000, delay = 2000, x = 30, delta = true, transition = easing.outQuad }) myTransitions[#myTransitions + 1] = transition.to(leftEyeCover, { time = 1000, delay = 4000, x = -500, delta = true, transition = easing.outQuad }) myTransitions[#myTransitions + 1] = transition.to(eye2, { time = 1000, delay = 4000, x = 30, delta = true, transition = easing.outQuad }) myTransitions[#myTransitions + 1] = transition.to(eye, { time = 1000, delay = 4000, x = -30, delta = true, transition = easing.outQuad }) myTransitions[#myTransitions + 1] = transition.to(leftEyeCover, { time = 1000, delay = 6000, x = 500, delta = true, transition = easing.outQuad }) myTransitions[#myTransitions + 1] = transition.to(eye2, { time = 1000, x = -30,delay = 6000, delta = true, transition = easing.outQuad }) myTransitions[#myTransitions + 1] = transition.to(eye, { time = 1000, x = 30,delay = 6000, delta = true, transition = easing.outQuad, onComplete = finishMove1 }) end if leftEyeMovement == 2 then local function finishMove2() button:setEnabled(true) button2:setEnabled(true) leftEyeMovement = 1 end leftEyeMovement = 3 myTransitions[#myTransitions + 1] = transition.to(leftEyeCover, { time = 1000, x = -825, delta = true, transition = easing.outQuad }) myTransitions[#myTransitions + 1] = transition.to(eye, { time = 1000, x = -30, delta = true, transition = easing.outQuad, onComplete = finishMove2 }) button3:setLabel("Alternate Test") end end button3 = widget.newButton{ label = "Alternating Test", fontSize = 30, width = 640, height = 90, left = 0, top = 750, onRelease = event3 } --------insert every button and image to group bellow group:insert( bg ) group:insert( eye ) group:insert( eye2 ) group:insert( sockets ) group:insert( button ) group:insert( button2 ) group:insert( button3 ) group:insert( rightEyeCover ) group:insert( leftEyeCover ) group:insert( backButton ) group:insert( infoButton ) end -- Called immediately after scene has moved onscreen: function scene:enterScene( event ) local group = self.view -- do nothing end -- Called when scene is about to move offscreen: function scene:exitScene( event ) for i = table.maxn(myTransitions), 1, -1 do if myTransitions[i] then transition.cancel(myTransitions[i]) myTransitions[i] = nil end end local group = self.view