"jbrave" wrote:
when exiting the poster screen, it goes back automatically to the search screen, buti dont think it goes back to the code that handles that screen. I guess thatis the meat of my question, when i exit the sub that builds and displays the poster screen, i dont see any way to get back to the sub displayposter() since the sub messageloop()is not called from sub displayposter() but from main(). should each successive screen be called from the sub that calls the previous screen?
You should be calling your messageloop() sub from each screen, and exiting that instance when you close the screen.
In a very simplified example, this is how I do my screens. Ordinarily I'd break these up into multiple source files, and make them more self contained... The main thing to notice here is that each screen has its own event/message loop that blocks the parent event loop until the screen is closed. This example uses a shared ListenForEvents() sub, but for readability (and to avoid a huge If/Then tree), you'd probably want a different one for each screen.
Sub Main()
m.MessagePort = CreateObject( "roMessagePort" )
poster = NewPosterScreen( "parameters like title, breadcrumb, etc" )
' show the poster screen and let it's event loop handle it's events
poster.Show()
' at this point, the last event loop has exited, and screens have
' closed, so we exit the app
End Sub
Function NewPosterScreen( some parameters to pass in ) As Object
poster = {
Screen: CreateObject( "roPosterScreen" ),
MessagePort: m.MessagePort,
Init: Poster_Init,
Show: Poster_Show,
ListenForEvents: ListenForEvents
}
poster.Init()
Return poster
End Function
Sub Poster_Init()
'Initialize poster screen details here
m.Screen.SetMessagePort( m.MessagePort )
End Sub
Sub Poster_Show()
' show the screen
m.Screen.Show()
' jump into local event loop
m.ListenForEvents()
End Sub
Function NewSprinboardScreen( some parameters to pass in ) As Object
poster = {
Screen: CreateObject( "roSpringboardScreen" ),
MessagePort: m.MessagePort,
Init: Springboard_Init,
Show: Springboard_Show,
ListenForEvents: ListenForEvents
}
poster.Init()
Return poster
End Function
Sub Springboard_Init()
'Initialize poster screen details here
m.Screen.SetMessagePort( m.MessagePort )
End Sub
Sub Springboard_Show()
' show the screen
m.Screen.Show()
' jump into local event loop
m.ListenForEvents()
End Sub
Sub ListenForEvents()
While True
msg = Wait( 0, m.MessagePort )
If msg <> invalid Then
If Type( msg ) = "roPosterScreenEvent" Then
' handle poster screen events
If msg.IsScreenClosed() Then
' screen is closed, exit this instance of the
' event loop
Exit While
Else If msg.IsListItemSelected() Then
springboard = NewSpringboardScreen()
' This will block until the springboard is closed
' at which point we'll re-enter this instance of the
' event loop
springboard.Show()
Else If msg.SomeOtherEvent Then
'blahblahblah
End If
Else If Type( msg ) = "roSpringboardScreenEvent" Then
If msg.IsScreenClosed() Then
' screen is closed, exit this instance of the
' event loop
Exit While
End If
End If
End If
End While
End Sub
My Channels: http://roku.permanence.com - Twitter: @TheEndlessDev
Instant Watch Browser (NetflixIWB), Aquarium Screensaver (AQUARIUM), Clever Clocks Screensaver (CLEVERCLOCKS), iTunes Podcasts (ITPC), My Channels (MYCHANNELS)