webview and composer scenes - webview not being removed

Hi

I’ve had a look through the forums for an answer to this question:

I have a tabview at the bottom of the screen that changes to different webviews whenever a button is pressed.  The issue is that when I goto a tabview that is not a webview - I cannot get rid of the webview.  I’ve tried the:

webView:removeSelf()

in the function:

function scene:hide( event ) – line 45

    local sceneGroup = self.view

    print(“in scene hide”)

    webView:removeSelf()  – line 48

end

the webview is created like:

local webView = native.newWebView( 0,0, display.viewableContentWidth,  display.viewableContentHeight - 50)

webView.anchorX = 0

webView.anchorY = 0

webView:request( “http://www.google.com” )

I can see in the logs that the scene:destroy is being called, but I get this error when it is called:

/Users/tgreco/Library/Application Support/Outlaw/Sandbox/6/overview.lua:48: in function </Users/tgreco/Library/Application Support/Outlaw/Sandbox/6/overview.lua:45>

?: in function ‘dispatchEvent’

?: in function ‘_listener’

?: in function <?:141>

?: in function <?:221>

 

Any suggestions ?

 

Thanks

Tonino

Hi Tonino,

Please check that you have the proper scope on the webView reference. Most likely, you are not providing the same reference, so when the scene is destroyed, Lua does not know which object you are referring to.

Take care,

Brent

Hi Brent

Thanks.  I managed to work it out.  I was not doing the removeSelf() in the right location. I was supposed to get it in the scenehide function as follows:

function scene:hide( event ) local sceneGroup = self.view if event.phase == "will" then if webView and webView.removeSelf then webView:removeSelf() webView = nil end end end&nbsp;

This works well and I am happy :wink:

Thanks

Tonino

Hi Tonino,

Please check that you have the proper scope on the webView reference. Most likely, you are not providing the same reference, so when the scene is destroyed, Lua does not know which object you are referring to.

Take care,

Brent

Hi Brent

Thanks.  I managed to work it out.  I was not doing the removeSelf() in the right location. I was supposed to get it in the scenehide function as follows:

function scene:hide( event ) local sceneGroup = self.view if event.phase == "will" then if webView and webView.removeSelf then webView:removeSelf() webView = nil end end end&nbsp;

This works well and I am happy :wink:

Thanks

Tonino