Forum Discussion

360tv's avatar
360tv
Streaming Star
13 years ago

ShowMessageDialog

so if I plop this code from the component reference into my appHomeScreen.brs...

Function ShowMessageDialog() As Void
port = CreateObject("roMessagePort")
dialog = CreateObject("roMessageDialog")
dialog.SetMessagePort(port)
dialog.SetTitle("[Message dialog title]")
dialog.SetText("[Message dialog text............]")
dialog.AddButton(1, "[button text]")
dialog.Show()
while true
dlgMsg = wait(0, dialog.GetMessagePort())
if type(dlgMsg) = "roMessageDialogEvent"
if msg.isScreenClosed()
exit while
end if
end if
end while
End Function


it freezes after it shows up. Button 1 doesn't do anything and I have to exit out of the app entirely. What's going on with that?

My goal is to create sort of a "Message Of The Day" kinda thing. But my first step is to get a simple dialog box to work. Then I'll address how to feed it the information I want (probably thru a separate xml feed).

3 Replies

  • There's no handler in there for the button selection. Modify it to handle the button selection.

    Function ShowMessageDialog() As Void
    port = CreateObject("roMessagePort")
    dialog = CreateObject("roMessageDialog")
    dialog.SetMessagePort(port)
    dialog.SetTitle("[Message dialog title]")
    dialog.SetText("[Message dialog text............]")
    dialog.AddButton(1, "[button text]")
    dialog.Show()
    while true
    dlgMsg = wait(0, dialog.GetMessagePort())
    if type(dlgMsg) = "roMessageDialogEvent" then
    if msg.isScreenClosed() then
    exit while
    else if msg.isButtonPressed() then
    ' This assumes you only have one button and you want it
    ' to close the dialog when selected, otherwise check
    ' msg.GetIndex() and respond appropriately
    dialog.Close()
    end if
    end if
    end while
    End Function
  • 360tv's avatar
    360tv
    Streaming Star
    How?

    As I'm reading the code, what you've typed in should make the dialog box close when you click the button (right?). But it dosen't.
  • Oops. I just copied and modified the code you posted earlier. The problem is that that code assigns the variable "dlgMsg" but checks "msg". Try this instead.

    Function ShowMessageDialog() As Void
    port = CreateObject("roMessagePort")
    dialog = CreateObject("roMessageDialog")
    dialog.SetMessagePort(port)
    dialog.SetTitle("[Message dialog title]")
    dialog.SetText("[Message dialog text............]")
    dialog.AddButton(1, "[button text]")
    dialog.Show()
    while true
    msg = wait(0, dialog.GetMessagePort())
    if type(msg) = "roMessageDialogEvent" then
    if msg.isScreenClosed() then
    exit while
    else if msg.isButtonPressed() then
    ' This assumes you only have one button and you want it
    ' to close the dialog when selected, otherwise check
    ' msg.GetIndex() and respond appropriately
    dialog.Close()
    end if
    end if
    end while
    End Function