How to select / change object from another composer scene

I’ve searched forums, google and stackoverflow for this solution. No luck, so here it goes:

Scene A : (creating public object)

someLine = display.newLine( 0,100, screenW,100 ) someLine:setStrokeColor( 0, 0, 0 )

Scene B : (changing public object)

someLine:setStrokeColor( 1, 1, 1 )

Changing object from scene A in scene B like in example above, does not work. Any idea how to get to that object without some weird workarounds?

Thank you so much! :slight_smile:

There are several ways to access objects in other scenes but there is a huge caveat…

You have to not destroy the off screen scene while it’s off screen.  If your scene gets destroyed it doesn’t matter if you can change things or not.  So lets say you’re keeping the scene in memory.

Your options are:

  1. Globals.  Globals are of course bad if you don’t know what you’re doing.

  2. Faux-Globals.  These are like globals without most of the badness of globals.  See: http://coronalabs.com/blog/2013/05/28/tutorial-goodbye-globals/

  3. Set variables inside the Composer scene object.    Look for docs on composer.setVariable and composer.getVariable. 

Rob

My mistake was using Globals in scene:Create, that’s why that change in my example didn’t work. I moved the change command to scene:Show and it works now.

Thanks Rob!

There are several ways to access objects in other scenes but there is a huge caveat…

You have to not destroy the off screen scene while it’s off screen.  If your scene gets destroyed it doesn’t matter if you can change things or not.  So lets say you’re keeping the scene in memory.

Your options are:

  1. Globals.  Globals are of course bad if you don’t know what you’re doing.

  2. Faux-Globals.  These are like globals without most of the badness of globals.  See: http://coronalabs.com/blog/2013/05/28/tutorial-goodbye-globals/

  3. Set variables inside the Composer scene object.    Look for docs on composer.setVariable and composer.getVariable. 

Rob

My mistake was using Globals in scene:Create, that’s why that change in my example didn’t work. I moved the change command to scene:Show and it works now.

Thanks Rob!