Roku Developer Program

Developers and content creators—a complete solution for growing an audience directly.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How to open new Scene Inside Main in Roku?

I'm asking a very dumb question I know. But I tried many ways but did not get the correct solution for this.
My Question is How to close and open a new Scene inside of the main My Code is :

sub StartSGDEXChannel(componentName, args)
    m.screen = CreateObject("roSGScreen")
    m.port = CreateObject("roMessagePort")
    m.screen.SetMessagePort(m.port)   
    scene = m.screen.CreateScene(componentName)
    
    scene.SetCertificatesFile("pkg:/certificates/cacert.crt")
    scene.InitClientCertificates()

    m.screen.Show()
    scene.ObserveField("exitChannel", m.port)
    scene.launch_args = args
    scene.signalBeacon("AppLaunchComplete")
    while (true)
        msg = Wait(0, m.port)
        msgType = Type(msg)
        ?"SGDEX :: msgType : "msgType
        if msgType = "roSGScreenEvent"
            if msg.IsScreenClosed() then return
        else if msgType = "roSGNodeEvent"
            field = msg.getField()
            data = msg.getData()
            if field = "exitChannel" and data = true then

                'Here I'm trying to do close the Main Scene and Open a new Scene.
                'I write below line it's close whole App
                 m.screen.close()
                         
                'I created one Sperate component and tried But it's not Working
                 m.scene = m.screen.CreateScene("SampleExample")
                 m.screen.show()
                 m.scene.setFocus(true)

            end if
        end if
    end while
end sub

Anyone, Please suggest or guide me on how to do this type of thing in Roku?

0 Kudos
1 REPLY 1
RokuJonathanD
Roku Employee
Roku Employee

Re: How to open new Scene Inside Main in Roku?

Hi @chaklasiyanikun,

Per the Scene reference doc, channels typically only have a single scene node in them, but can have multiple screens.

You can take a look at our getting started sample for a channel with a single screen or the master sample channel on how to handle multiple screens.

Thanks,

Jonathan

0 Kudos