removing scroll view from scene

I have one scene in which inside a function a scrollview is being generated and added to it some text elements. Now when I go to another scene, the scrollview is not getting removed. Even if I add a background image in the second scene, the scrollview is shown on top of it. I would like to know a way to remove or hide or send it back to the new scene… Thanks in advance…

Sounds like you’re not adding the scrollView to your scene’s view group.

Rob

As I am new to corona, I don’t know how to add and object into sceneGroup from another function other than the create function… Pls tell me how ? When I try to add it to a global sceneGroup which I created, it returns nil value error…

At the top of your .lua file:

[lua]

local sceneGroup = display.newGroup()

[/lua]

Then remove the local from the sceneGroup = self.view part of your scene: functions.

You can then add objects to sceneGroup from anywhere in the scene.

I will post the relevant code snippets from my scene lua file

local function onDeptPress( event )

    local sceneGroup = display.newGroup() — is this usage correct… ?

    switch = event.target

    deptId = switch.id

    local deptHeader = “”

    removeData()

    

    if deptId== “ce” then

        deptHeader = “Civil”

    end

    if deptId == “me” then

        deptHeader = “Mechanical”

    end

    --…

        --…

        --…

    --…

    local taskBarTop = display.newRect(0, 0, display.contentWidth, display.contentHeight/15)

    taskBarTop:setFillColor(0.255,0.255,0.858)

    taskBarTop.x = display.contentCenterX

    taskBarTop.y = display.contentCenterY/15

    deptName = display.newText( deptHeader, 50, 50, native.systemFont, 28 )

    deptName:setFillColor( 0, 1, 0 )

    deptName.x = display.contentWidth/2

    deptName.y = 16

    loadData()

    ------------------display the buttons and names--------start---------------------

   

    myData.dataScrollView = widget.newScrollView({

        width = 270,

        height = 395,

        scrollWidth = 260,

        scrollHeight = 900,

        horizontalScrollDisabled = true,

        backgroundColor = { 0.9, 0.9, 0.9 }

    })

    myData.dataScrollView.x = display.contentCenterX+18

    myData.dataScrollView.y = display.contentHeight/2-20

    sceneGroup:insert(dataScrollView) –   error shows when this line is added

    --…

    --…

    numList[i] = display.newText(people[i].Phones,50, 200, native.systemFont, 13)

    numList[i]:setFillColor( 1, 0, 1,0.7 )  

    numList[i].x = nameList[i].x +5

    numList[i].y = yOffset+10

    numList[i].anchorX = 0

    myData.dataScrollView:insert(numList[i])

    --…

    --similarly some textList is also added to the scrollview

    --…

    --…

end

local function handleDataBtn( … )

    composer.gotoScene(“editData”)

end

---- when i switch to editData scene, the scrollview already created in menu lua is still showing up with the items added to it

-----I tried in many ways but no use… I would like to know how to use the other functions of show, hide destroy etc…

thanks

thanks sherman, let me try that… :slight_smile:

If you’re using composer, inside scene:create() and scene:show(), there should already be a line:

local sceneGroup = self.view

Any objects you create in those two functions you need to insert them:

local myObject = display.newRect( 100, 100, 50, 50 ) sceneGroup:insert( myObject )

You should probably leave the “local” on the declaration.

If you’re creating objects in some other function in the scene that’s not inside scene:create() or scene:show() then you can access the scene’s view group like this:

local sceneGroup = scene.view local myObject = display.newRect( 100, 100, 50, 50 ) sceneGroup:insert( myObject )

If you’re not using Composer, then you can create  your own display.newGroup() as suggested above.

Rob

Yesssss… Rob, that worked great…thanks a lot… spent 3 nights and two days…

thanks again…

Sounds like you’re not adding the scrollView to your scene’s view group.

Rob

As I am new to corona, I don’t know how to add and object into sceneGroup from another function other than the create function… Pls tell me how ? When I try to add it to a global sceneGroup which I created, it returns nil value error…

At the top of your .lua file:

[lua]

local sceneGroup = display.newGroup()

[/lua]

Then remove the local from the sceneGroup = self.view part of your scene: functions.

You can then add objects to sceneGroup from anywhere in the scene.

I will post the relevant code snippets from my scene lua file

local function onDeptPress( event )

    local sceneGroup = display.newGroup() — is this usage correct… ?

    switch = event.target

    deptId = switch.id

    local deptHeader = “”

    removeData()

    

    if deptId== “ce” then

        deptHeader = “Civil”

    end

    if deptId == “me” then

        deptHeader = “Mechanical”

    end

    --…

        --…

        --…

    --…

    local taskBarTop = display.newRect(0, 0, display.contentWidth, display.contentHeight/15)

    taskBarTop:setFillColor(0.255,0.255,0.858)

    taskBarTop.x = display.contentCenterX

    taskBarTop.y = display.contentCenterY/15

    deptName = display.newText( deptHeader, 50, 50, native.systemFont, 28 )

    deptName:setFillColor( 0, 1, 0 )

    deptName.x = display.contentWidth/2

    deptName.y = 16

    loadData()

    ------------------display the buttons and names--------start---------------------

   

    myData.dataScrollView = widget.newScrollView({

        width = 270,

        height = 395,

        scrollWidth = 260,

        scrollHeight = 900,

        horizontalScrollDisabled = true,

        backgroundColor = { 0.9, 0.9, 0.9 }

    })

    myData.dataScrollView.x = display.contentCenterX+18

    myData.dataScrollView.y = display.contentHeight/2-20

    sceneGroup:insert(dataScrollView) –   error shows when this line is added

    --…

    --…

    numList[i] = display.newText(people[i].Phones,50, 200, native.systemFont, 13)

    numList[i]:setFillColor( 1, 0, 1,0.7 )  

    numList[i].x = nameList[i].x +5

    numList[i].y = yOffset+10

    numList[i].anchorX = 0

    myData.dataScrollView:insert(numList[i])

    --…

    --similarly some textList is also added to the scrollview

    --…

    --…

end

local function handleDataBtn( … )

    composer.gotoScene(“editData”)

end

---- when i switch to editData scene, the scrollview already created in menu lua is still showing up with the items added to it

-----I tried in many ways but no use… I would like to know how to use the other functions of show, hide destroy etc…

thanks

thanks sherman, let me try that… :slight_smile:

If you’re using composer, inside scene:create() and scene:show(), there should already be a line:

local sceneGroup = self.view

Any objects you create in those two functions you need to insert them:

local myObject = display.newRect( 100, 100, 50, 50 ) sceneGroup:insert( myObject )

You should probably leave the “local” on the declaration.

If you’re creating objects in some other function in the scene that’s not inside scene:create() or scene:show() then you can access the scene’s view group like this:

local sceneGroup = scene.view local myObject = display.newRect( 100, 100, 50, 50 ) sceneGroup:insert( myObject )

If you’re not using Composer, then you can create  your own display.newGroup() as suggested above.

Rob

Yesssss… Rob, that worked great…thanks a lot… spent 3 nights and two days…

thanks again…