Pause/Resume transition doesn't work

In “scene1” I have this code:

local trans function transition1( obj )     local clojure = function() obj.width = 0; transition1(obj) end     local options = {         width = 200,         time = 3000,         onComplete = clojure     }     trans = transition.to( obj, options ) end // Scene Create: local rect = display.newRect(sceneGroup, 300, 300, 0, 20) transition1(rect) // Scene Show: elseif ( phase == "did" ) then transition.resume(transition1)    end

When I click on a button in “scene1” this code runs:

function establishEvent(  )     transition.pause(transition1)     composer.gotoScene ( "scene2" ) end

Back from “scene2” to “scene1” the transition doesn’t resume. At first, I thought it’s because the transition gets called first in “Scene Create” then resumed in “Scene SHow” but after I used a boolean to check if it’s the first time the transition runs, the result was the same.

What am I doing wrong here?

edit:

// Scene Show: elseif ( phase == "did" ) then &nbsp; &nbsp; transition.resume(trans)&nbsp; &nbsp; \<\<-- passing the variable that holds the transition end

function establishEvent( &nbsp;) &nbsp; &nbsp; transition.pause(trans) \<\<-- passing the variable that holds the transition &nbsp; &nbsp; composer.gotoScene ( "scene2" ) end

I can tell you that is wrong, but I can’t understand what you’re trying to do so I cannot  give you code to replace it.

This is one way to cancel a transition:

local obj = display.newCircle( 10, 10, 10 ) local myTrans = transition.to( obj, { x = 1000, time = 2000 } ) -- now wait 500 ms and cancel the transition timer.performWithDelay( 500, function() transition.cancel( myTrans ) end )

However I find this better as it cancels all active transition on an object:

local obj = display.newCircle( 10, 10, 10 ) -- first transition transition.to( obj, { x = 1000, time = 2000 } ) -- first transition transition.to( obj, { y = 500, time = 2000 } ) -- now wait 500 ms and cancel ALL transitions on the object timer.performWithDelay( 500, function() transition.cancel( obj ) end )

Please go re-read the transition docs.

https://docs.coronalabs.com/api/library/transition/index.html

Note: You don’t pass functions to cancel(), pause(), resume(), you pass handles (transition references), object IDs, or tags.

What I want is to pause the transition when changing to another scene, then resume the transition after going back to the original scene. I don’t want to cancel it. 

You cannot pause a transition by passing a reference to the function that created it

Edited the code so now, I’m passing the variable itself and not the function ( silly mistake) 
The transition now gets “paused”, but the  “resume” problem still stands.

Check the edits above. 

Scene2 cannot access a local declared in scene1.

If you mean a transition declared local in scene1 then when you back to scene1 (from scene2) you are referencing a new local and not your original one.

You need to do some reading on scope.  

“Scene2” isn’t accessing anything in “Scene1”.
1- In “Scene1” I declare “trans” then define it in function “transition1”

2- When I leave “Scene1” I call: “transition.pause(trans)”   – Gets paused

3- When I go back to that scene, I call: “transition.resume(trans)”  which has already been defined once before. – Doesn’t resume

I can tell you that is wrong, but I can’t understand what you’re trying to do so I cannot  give you code to replace it.

This is one way to cancel a transition:

local obj = display.newCircle( 10, 10, 10 ) local myTrans = transition.to( obj, { x = 1000, time = 2000 } ) -- now wait 500 ms and cancel the transition timer.performWithDelay( 500, function() transition.cancel( myTrans ) end )

However I find this better as it cancels all active transition on an object:

local obj = display.newCircle( 10, 10, 10 ) -- first transition transition.to( obj, { x = 1000, time = 2000 } ) -- first transition transition.to( obj, { y = 500, time = 2000 } ) -- now wait 500 ms and cancel ALL transitions on the object timer.performWithDelay( 500, function() transition.cancel( obj ) end )

Please go re-read the transition docs.

https://docs.coronalabs.com/api/library/transition/index.html

Note: You don’t pass functions to cancel(), pause(), resume(), you pass handles (transition references), object IDs, or tags.

What I want is to pause the transition when changing to another scene, then resume the transition after going back to the original scene. I don’t want to cancel it. 

You cannot pause a transition by passing a reference to the function that created it

Edited the code so now, I’m passing the variable itself and not the function ( silly mistake) 
The transition now gets “paused”, but the  “resume” problem still stands.

Check the edits above. 

Scene2 cannot access a local declared in scene1.

If you mean a transition declared local in scene1 then when you back to scene1 (from scene2) you are referencing a new local and not your original one.

You need to do some reading on scope.  

“Scene2” isn’t accessing anything in “Scene1”.
1- In “Scene1” I declare “trans” then define it in function “transition1”

2- When I leave “Scene1” I call: “transition.pause(trans)”   – Gets paused

3- When I go back to that scene, I call: “transition.resume(trans)”  which has already been defined once before. – Doesn’t resume