Hey guys. There are two ways to solve this:
1. Use file level locals (GOOD):
local storyboard = require( "storyboard" ) local scene = storyboard.newScene() local myImage -- Now visibile to createScene() and enterScene() function scene:createScene( event ) local sceneGroup = self.view myImage = display.newImage( sceneGroup, "image.png" ) end function scene:enterScene( event ) local sceneGroup = self.view transition.to( myImage, { timer =1000, x =10 } ) end
2. Use the group that storyboard gives you and attach a ‘variable collector’. This will be visible in all ** of this scene’s **** functions, and will be automatically removed when storyboard destroys the scene (BETTER in many cases).**
local storyboard = require( "storyboard" ) local scene = storyboard.newScene() function scene:createScene( event ) local sceneGroup = self.view local myData = {} sceneGroup.data = myData myData.myImage = display.newImage( sceneGroup, "image.png") end function scene:enterScene( event ) local sceneGroup = self.view local myData = sceneGroup.data transition.to(myData.myImage, { timer =1000, x =10 } ) end
[hr]
Note: I also made some corrections to the original code:
-
You created a newImage(), but did not insert it into sceneGroup. If you don’t do this, that scene and storyboard will not manage it for you. It gets placed in the top-level group by default and will not be removed or hidden if the scene changes.
-
In one scene: callback, you called the group ‘sceneGroup’ and in the other you called it ‘scene’.
2a. Calling it scene was wrong as that is the name you’re using for your local ‘scene’ as created/provided by storyboard.
2b. Whatever you call the variable ‘event.view’ when you place it in a local, always use the same name in your callbacks or it will be very confusing later.