Roku Developer Program

Developers and content creators—a complete solution for growing an audience directly.
cancel
Showing results for 
Search instead for 
Did you mean: 
jeremie
Level 7

How to realy destroy a Panel

Hi,

I have a PanelSet and when I navigate I add some panels progressively. When I back to the first screen, in the debug console, when I use sgnodes roots I see old screens not linked to the root (and in memory ?)


function init()
   m.panelset = createObject("roSGNode", "PanelSet")
   m.panelset.observeField("isGoingBack","onGoBack")
   m.panelset.translation = [0,0]
   m.top.appendChild(m.panelset)
   addScreen("HomeScreen",{})
end function

function addScreen(screenName,screenData)
    m.currentScreen = m.panelset.createChild(screenName)
    m.currentScreen.leftPosition = 0
    m.currentScreen.observeField("mainBackground", "onChangeMainBackground")
    m.currentScreen.observeField("nextScreen", "onNextScreen")
    m.currentScreen.screenData = screenData
    m.currentScreen.setFocus(true)
end function

function onGoBack(e)
    print "on go back"
    if (e.getData() = true) then
        print "removing current screen"
        m.currentScreen.unobserveField("mainBackground")
        m.currentScreen.unobserveField("nextScreen")
    end if
end function


what can I do to completly destroy my panels ?

best regards,
Jeremie.
0 Kudos
1 Reply
jeremie
Level 7

Re: How to realy destroy a Panel

oups, it's noob fail ^^

I used m.currentScreen but when I go back m.currentScreen is not updated. My new script is working with a screenQueue 


function init()
   m.screenQueue = CreateObject("roArray", 0, true)
   m.background = m.top.findNode("background")   
   m.panelset = createObject("roSGNode", "PanelSet")
   m.panelset.observeField("isGoingBack","onGoBack")
   m.panelset.translation = [0,0]
   m.top.appendChild(m.panelset)
   addScreen("HomeScreen",{})
end function



function addScreen(screenName,screenData)
   currentScreen = m.panelset.createChild(screenName)
   currentScreen.leftPosition = 0
   currentScreen.observeField("mainBackground", "onChangeMainBackground")
   currentScreen.observeField("nextScreen", "onNextScreen")
   currentScreen.screenData = screenData
   currentScreen.setFocus(true)
   m.screenQueue.push(currentScreen)
end function

function onGoBack(e)
   if (e.getData() = true) then
       oldScreen = m.screenQueue.Pop()
       oldScreen.unobserveField("mainBackground")
       oldScreen.unobserveField("nextScreen")
   end if
end function
0 Kudos