Roku Developer Program

Join our online forum to talk to Roku developers and fellow channel creators. Ask questions, share tips with the community, and find helpful resources.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
chaklasiyanikun
Roku Guru

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
Community Moderator
Community Moderator

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
Need Assistance?
Welcome to the Roku Community! Feel free to search our Community for answers or post your question to get help.

Become a Roku Streaming Expert!

Share your expertise, help fellow streamers, and unlock exclusive rewards as part of the Roku Community. Learn more.