roTextScreen button problem

I just created a TextScreen component with one button. The screen works fine, but the button cannot be accessed. The 4-way pad on the remote does nothing. The button is not active. Can anyone see any problems with my code?

Thanks - Kenny

screen = CreateObject("roTextScreen")
    port = CreateObject("roMessagePort")
    screen.SetMessagePort(port)
	
	
    details = aFunction(FN)
    screen.SetText(details.description)
    screen.AddButton(1, "Back")
    screen.show()
    dialog.Close()
    while (true)
        msg = wait(0, port)
        if type(msg) = "roTextScreenEvent"
            if msg.isScreenClosed()
				exit while
            else if msg.isButtonPressed()
				exit while
            endif            
        endif
       
    end while
	screen.Close()