help on removing a scrollView on storyboard.

I have a scroll View in my code, it works fine, but I don’t know how to remove it once I go to another scene.

I thought it was going to work just like the buttons.

if buttonGame then             buttonGame:removeSelf()             buttonGame = nil         end                  if scrollView then             scrollView:removeSelf()             scrollView = nil         end

In the destroy scene, but it did not work.

This is the scroll view code

local scrollView = widget.newScrollView {     left = 500,     top = 200,     width = 400,     height = 200,     scrollWidth = 400,     scrollHeight = 200,     maskFile = "images/maskTest.png",     --bgColor = {0, 0, 0} } local function levelTap(event)     local pad = event.target     print("level chosen: ", pad.idx)     storyboard.gotoScene( "mainMenu", "fromRight", 200 ) end local monster = display.newImage ("images/testBg.png")     monster.x = 500     monster.y = scrollView.height / 2     scrollView:insert(monster) local trebleApart = 120 for idx = 1, 3 do     local lpad = display.newImageRect("images/trebleClef.png", 71, 182)     lpad.x = (idx \* trebleApart)     lpad.y = (scrollView.height / 2) - 10     lpad.idx = idx     lpad:addEventListener ("tap", levelTap)     scrollView:insert(lpad)          local levelText = display.newText ("Level " .. tostring(idx), 0, 0, "Helvetica", 16 )     levelText:setTextColor(0, 134, 146)     levelText.x = (idx \* trebleApart)     levelText.y = scrollView.height / 2 + 85     scrollView:insert(levelText)          if idx == 11 then         lpad.alpha = 0         levelText.alpha = 0     end end

Thanks for your help

Victor

Remove it in exitScene

Thanks…JonPM - for taking the time to answer… but I am very new

could you please let me know how? what code should I use…

–display.remove(scrollView)

–display.remove(object)

–if scrollView then

      scrollView:removeSelf()

      scrollView = nil

– scrollView:remove

– or maybe a function on the exit scene to remove it

– or maybe something else that I don’t know

Thanks

I would use:
scrollView:removeSelf()
scrollView = nil

The reason it’s not working in destroyScene is the scene is still active in memory even when it moves off screen and is not visible(until the system decides to free up more memory). exitScene is called everytime the scene is changed.

Where did you learn to do this?

How long have you been programming?

Thanks a lot! it work really good. I had to change – local scrollView for just scrollView

and put the local scrollView on top.

I’m learning, little by little by I think I’m doing good for only 5 months!

Thanks a lot.

Victor

If you put your scrollView in your scene’s group, it will be disposed of when the scene gets disposed.

Rob, I had a question about that.  Do you need to add all of your display objects within a scrollview to the scene’s group as well, or just to the scrollview?  

Just the scrollView.  It’s a displayGroup and items can only be in one group at a time, so putting it into group would remove it from the scrollView.

Remove it in exitScene

Thanks…JonPM - for taking the time to answer… but I am very new

could you please let me know how? what code should I use…

–display.remove(scrollView)

–display.remove(object)

–if scrollView then

      scrollView:removeSelf()

      scrollView = nil

– scrollView:remove

– or maybe a function on the exit scene to remove it

– or maybe something else that I don’t know

Thanks

I would use:
scrollView:removeSelf()
scrollView = nil

The reason it’s not working in destroyScene is the scene is still active in memory even when it moves off screen and is not visible(until the system decides to free up more memory). exitScene is called everytime the scene is changed.

Where did you learn to do this?

How long have you been programming?

Thanks a lot! it work really good. I had to change – local scrollView for just scrollView

and put the local scrollView on top.

I’m learning, little by little by I think I’m doing good for only 5 months!

Thanks a lot.

Victor

If you put your scrollView in your scene’s group, it will be disposed of when the scene gets disposed.

Rob, I had a question about that.  Do you need to add all of your display objects within a scrollview to the scene’s group as well, or just to the scrollview?  

Just the scrollView.  It’s a displayGroup and items can only be in one group at a time, so putting it into group would remove it from the scrollView.