How to clear objects when loading new scene?

Hi,

I am using the storyboard to load scenes for pages. I have it navigate to one page that has a few controls on it. I am then trying to go to another scene page but it does not. All of the controls and images are still there showing.

Here is where I have put the removeSelf lines. Is this not available for all of the controls out there?

-- Called when scene is about to move offscreen:  
function scene:exitScene( event )  
 local group = self.view  
  
 imgHeader:removeEventListener( "touch", imgHeader )  
 imgHeader.removeSelf()  
 myImage:removeSelf()  
 btnPost:removeSelf()  
 btnCancel:removeSelf()  
 field1:removeSelf()  
  
end  

Here is where I am calling to go to another scene page:

local onbtnCancelEvent = function (event )  
 if event.phase == "release" then  
 storyboard.gotoScene( "SceneTwo", "fade", 300 )  
 end  
end  

Thanks!!
[import]uid: 184193 topic_id: 33952 reply_id: 333952[/import]

With storyboard you don’t need to remove the objects explicitly as you are doing above.

At the top of your .lua file, set up local references to any objects you intend to create later on in the scene. This enables you to reference them from other functions in the scene to apply adjustments, transitions etc

[lua]local imgHeader
local myImage[/lua]

Then create the objects within createScene, BUT make sure you insert them into the display group:

[lua]group:insert(imgHeader)
group:insert(myImage)[/lua]

Anything inserted into group will automatically be discarded by Storyboard on changing scenes. You will still need to remove timers and event listeners though.

[import]uid: 93133 topic_id: 33952 reply_id: 134958[/import]

With storyboard you don’t need to remove the objects explicitly as you are doing above.

At the top of your .lua file, set up local references to any objects you intend to create later on in the scene. This enables you to reference them from other functions in the scene to apply adjustments, transitions etc

[lua]local imgHeader
local myImage[/lua]

Then create the objects within createScene, BUT make sure you insert them into the display group:

[lua]group:insert(imgHeader)
group:insert(myImage)[/lua]

Anything inserted into group will automatically be discarded by Storyboard on changing scenes. You will still need to remove timers and event listeners though.

[import]uid: 93133 topic_id: 33952 reply_id: 134958[/import]