Forum Discussion

alx's avatar
alx
Visitor
9 years ago

Simple Grid with Details and Video

Newbie question...

I'm trying to understand the logic behind hiding and showing screens in the Simple Grid demo.

So I added a back button in the Details Scene to return to the Home Scene.

I must be doing something wrong because I simply can't make it work.

Any pointers on how to switch between scenes?

6 Replies

  • TheEndless's avatar
    TheEndless
    Channel Surfer
    Typically, you'd only have one scene with multiple components that represent each screen. These "screen" components are shown or hidden using their "visible" attribute. The example you're looking at works the same way (i.e., there is no "Details Scene" rather a details screen component that resides in the HomeScene"). In it, the "GridScreen" component is the "home" screen. Look in the OnKeyEvent function in HomeScene.brs and you should see how the back button presses are used to show and hide the details screen.
  • I see that on the HomeScene >> OnkeyEvent the fiscal back button is handled.

    But if I do the same on the DetailsScreen the roku freezes.
    This is the code I added to to Details Screen:

    ' on Button press handler
    Sub onItemSelected()
    print "play button pressed"

    ' first button is Play
    if m.top.itemSelected = 0
    m.videoPlayer.visible = true
    m.videoPlayer.setFocus(true)
    m.videoPlayer.control = "play"
    m.videoPlayer.observeField("state", "OnVideoPlayerStateChange")
    end if
    ' second button is Back
    if m.top.itemSelected = 1
    print "back pressed"

    m.gridScreen = m.top.findNode("GridScreen")
    m.gridScreen.visible = "true"
    m.detailsScreen.visible = "false"
    m.gridScreen.setFocus(true)

    end if
    End Sub


    Any idea what I am missing?
  • TheEndless's avatar
    TheEndless
    Channel Surfer
    Ah.. you're not trying to capture a remote button press, but rather a poster you've added to the grid. In that case, I think you'd need to set the value of a field on the DetailsScreen that the Scene is observing. Perhaps a field called "close" (similiar to how dialogs work). The scene will observe that field and change the visibility when it's value changes.

    The code above won't work, because your details screen doesn't have a reference to m.gridScreen or m.detailsScreen. Those are defined in the scene script.
  • Yes, I'm trying to add a back button on screen.

    This is what the debugger is showing:

    086: m.gridScreen = m.top.findNode("GridScreen")
    087:* m.gridScreen.visible = true
    Invalid value for left-side of expression. (runtime error &he4) in ...



    Or is there a way to create a "back-button pressed" event?
  • TheEndless's avatar
    TheEndless
    Channel Surfer
    "alx" wrote:
    Yes, I'm trying to add a back button on screen.

    This is what the debugger is showing:

    086: m.gridScreen = m.top.findNode("GridScreen")
    087:* m.gridScreen.visible = true
    Invalid value for left-side of expression. (runtime error &he4) in ...
    Or is there a way to create a "back-button pressed" event?

    That's because the DetailsScreen doesn't know about GridScreen. GridScreen is part of the Scene, not the DetailsScreen, so running m.top.findNode in DetailsScreen is going to return invalid, resulting in the error you're getting. You'll need to add a field to DetailsScreen that the Scene can observe, so it can close the DetailsScreen.
  • Thanks for your help. I'm still struggling to get a grip on how to "close" the DetailsScreen.



    is there a way to create a "back-button pressed" event?