[SOLVED] Map object not removed changing storyboard scenes

Hi friends,

Here is the code for the storyboard scene where I have the map:

[lua]-- scene map
function scene1map:createScene( event )
local group = self.view
local myMap = native.newMapView( 0, 110, 320, 322 )
myMap.mapType = “normal”
group:insert( myMap )
end
scene1map:addEventListener( “createScene”, scene1map )[/lua]

Also, I have a listener on a button to change acene:

[lua]storyboard.gotoScene( “scene2” )[/lua]

The problem is that when I change scene the map will persist on the screen. I have other elements on the map scene that are removed properly.

Help please, thanks. [import]uid: 158485 topic_id: 33521 reply_id: 333521[/import]

Native objects like native.textField and native.mapView are not display objects that are controlled by Corona’s display group system. They always sit above any display objects. Therefore storyboard cannot manage the removal of these items.

You need to probably create the mapView in your enterScene() function and remove it in your exitScene() function by hand.

[import]uid: 199310 topic_id: 33521 reply_id: 133205[/import]

Thanks for your support Rob.

I made my map object global instead of local and then added:

[lua]function scene1map:exitScene( event )
myMap:removeSelf()
end[/lua]

That did the trick of removing the object when leaving the scene. However if I enter the scene again the map object is not recreated. Is there a way I can force the map creation? [import]uid: 158485 topic_id: 33521 reply_id: 133251[/import]

I got it :slight_smile:

I moved the object creation from createScene to enterScene event.
This way the object is always created when accessing the scene.

Thakns [import]uid: 158485 topic_id: 33521 reply_id: 133264[/import]

Glad it’s working for you. [import]uid: 199310 topic_id: 33521 reply_id: 133306[/import]

Native objects like native.textField and native.mapView are not display objects that are controlled by Corona’s display group system. They always sit above any display objects. Therefore storyboard cannot manage the removal of these items.

You need to probably create the mapView in your enterScene() function and remove it in your exitScene() function by hand.

[import]uid: 199310 topic_id: 33521 reply_id: 133205[/import]

Thanks for your support Rob.

I made my map object global instead of local and then added:

[lua]function scene1map:exitScene( event )
myMap:removeSelf()
end[/lua]

That did the trick of removing the object when leaving the scene. However if I enter the scene again the map object is not recreated. Is there a way I can force the map creation? [import]uid: 158485 topic_id: 33521 reply_id: 133251[/import]

I got it :slight_smile:

I moved the object creation from createScene to enterScene event.
This way the object is always created when accessing the scene.

Thakns [import]uid: 158485 topic_id: 33521 reply_id: 133264[/import]

Glad it’s working for you. [import]uid: 199310 topic_id: 33521 reply_id: 133306[/import]