Forum Discussion

bounce's avatar
bounce
Newbie
8 years ago

Close Child Scene

I've attached my code. Pretty straightforward I've read previous articles stating that I can only close a child scene by the parent scene. Is there another way of doing this for the sake of clean code?




<component name = "scene" extends = "Group" initialFocus = "textrectangle" >

<?xml version="1.0" encoding="utf-8" ?>




<script type = "text/brightscript" >
        
        <![CDATA[
            
            sub init()
             end sub
             
             function onKeyEvent(key as String, press as Boolean) as Boolean
             
                if press then
                    if key = "back"
                        print "destroy window"
                        m.screen = m.top.findNode("scene")
                        m.top.removeChild(m.screen)
                        m.screen = invalid
                        
                        return true
                    end if
                end if
        
             
                return false
             end function
            ]]>

   </script>
  <children>

    <Rectangle
      id = "textRectangle"
      width = "1020"
      height = "560"
      translation="[0,0]"
      color = "0x000000FF" >

           <Label
            id="text"
            height="44"
            width="0"
            font="font:MediumBoldSystemFont"
            text = "Text"
            horizAlign = "left"
            vertAlign = "center"
            translation="[10,520]" />
    </Rectangle>
  </children>
</component>

4 Replies

  • So this is functioning as you'd like and you're just looking for alternative ways to do it, or is something going wrong with what you have here?
    If it's already functioning correctly for you, my opinion of the cleanliness is that this is fine.  What don't you like?
  • I cannot close this child scene with the following code. The key event occurs but doesn't destroy the scene. I would like to destroy the scene from this xml file and not from the main scene for the sake of not adding more complex code to the main scene.
  • Oh I don't think you can do this.  In the RSG app I'm working on, the main scene has tons of logic as it's the top level controller of everything happening.  There's just one scene that stays open the whole time and opens other components by attaching them as child to its containers.  And the one scene has all the logic for controlling (showing and hiding) those containers as if they are different scenes.
  • Agree with joetesta, the conventional approach is to have your screen management logic in the home scene. We have tons of logic to show/hide child nodes in a home scene's key handler.