Reloading buttons in Audio Player

Hi all,

I’m pulling my hair out and need some help. I’m trying to update my previously working audio player app to allow for refresh of the player buttons based on playstate. I keep getting errors on the ‘function reloadbuttons (screen as object, isplaying as boolean, ispaused as boolean)’ line, saying that ‘screen’ is uninitialized. What am I missing (while I still have hair on my head)…

Function showAudioSpringboardScreen(item as object)
    screen = CreateObject("roSpringboardScreen")
    port = screen.getmessageport()
    busydialog=CreateObject("roOneLineDialog") ' creates a dialog box
    print "showAudioSpringboardScreen"
	print item
	print item.title
	
    
    busydialog.SetMessagePort(port)
    screen.AllowUpdates(false)
	screen.SetBreadcrumbText("Live Audio Stream","")
	screen.SetBreadcrumbEnabled(true)
    screen.SetContent(item)
    screen.Show()
	audio=createobject("roaudioplayer")
	isplaying=false
	ispaused=false
	reloadbuttons(screen,playing,paused)

   	screen.SetDescriptionStyle("audio") 'audio, movie, video, generic
                                        ' generic+episode=4x3,

    screen.SetStaticRatingEnabled(false)
    screen.AllowUpdates(true)
    screen.setadurl("http://crntalk.com/podcast/roku/app/images/adbanner_hd.png","http://crntalk.com/podcast/roku/app/images/adbanner_sd.png")
	screen.setAdSelectable(true)

    downKey=3
    selectKey=6

    while true
        msg = wait(0, aud.GetMessagePort())

'*******************
if type(msg)="roAudioPlayerEvent"	
	print msg.getmessage()
	if msg.isStatusMessage() and msg.GetMessage() = "startup progress" then
	busydialog.SetMessagePort(aud.GetmessagePort()) 'sets a message port for the dialog box
	busydialog.SetTitle("Your CRN Live Stream will begin momentarily. ") 'displays a line of text for the dialog box title
	busydialog.ShowBusyAnimation() ' enables a spinning animation
	busydialog.Show() ' makes the dialog box and busy animation display
	
	else if msg.isStatusMessage() and msg.GetMessage() = "start of play" then
	busydialog.Close()

	else if msg.isStatusMessage() and msg.GetMessage() = "end of playlist" then
	busydialog.Close()
	busydialog=CreateObject("roOneLineDialog") ' creates a dialog box
	busydialog.SetMessagePort(aud.GetmessagePort()) 'sets a message port for the dialog box
	busydialog.SetTitle("The Connection Timed Out.") 'displays a line of text for the dialog box title
	busydialog.Show() ' makes the dialog box

	busydialog.Close()
	endif

'*******************

else if type(msg) = "roSpringboardScreenEvent"
    if msg.isScreenClosed()
    print "Screen closed"
    exit while 

else if msg.isadselected() then
	print "Ad Selected"
	showParagraphScreen(true)
              
else if msg.isButtonPressed()
    print "Button pressed: "; msg.GetIndex(); " " msg.GetData()
    if msg.GetIndex() = 0 then
    print "Audio Player Selected"
	audio.SetMessagePort (port)

	if item <> invalid and type(m) = "roAssociativeArray"
		print "Array OK"
		print item.url
		Print "Getting Stream"
		audio.stop()
        audio.addContent(item)	
		audio.play()
		isplaying=false
		ispaused=false
	reloadbuttons(screen,isplaying,ispaused)

Else if isplaying and not ispaused then

            	Audio.pause()
				isplaying=true
                ispaused=false
                reloadbuttons(screen,isplaying,ispaused)

else if isplaying and ispaused then

                audio.resume()
                isplaying=true
                ispaused=true
                reloadbuttons(screen,isplaying,ispaused)

	else print "invalid"
		'return -1
	end if

    			else if msg.GetIndex() = 1
				print "Audio Stop"
				audio.stop()
                islaying=false
                ispaused=false
                reloadbuttons(screen,isplaying,ispaused)

                else if msg.GetIndex() = 2 then
					if item.title = "CRN1" then
                         Schedule1(true)
					     print "Show Schedule"
					else if item.title = "CRN2" then
						 Schedule2(true)
					     print "Show Schedule"
					else if item.title = "CRN3" then
						 Schedule3(true)
					     print "Show Schedule"
					else if item.title = "CRN4" then
						 Schedule4(true)
					     print "Show Schedule"
					else if item.title = "CRN5" then
						 Schedule5(true)
					     print "Show Schedule"
					else if item.title = "CRN6" then
						 Schedule6(true)
					     print "Show Schedule"
					else if item.title = "CRN7" then
						 Schedule7(true)
						 print "Show Schedule"
					else print "No Schedule Loaded"
						end if
				else if msg.GetIndex() = 3
						showParagraphScreen(true)
                else if msg.GetIndex() = 4
                        return true
                    endif
            else
                print "Unknown event: "; msg.GetType(); " msg: "; msg.GetMessage()
            endif
        else 
            print "wrong type.... type=";msg.GetType(); " msg: "; msg.GetMessage()
        endif
    end while

    return screen
End Function

Function reloadButtons(screen as object, isplaying as Boolean, ispaused as Boolean)

                               screen.clearbuttons()
                               If not isplaying then
                               screen.addbutton(0,"Play")
                               Else if isplaying and not ispaused then
                               screen.addbutton(0,"Pause")
                               screen.addbutton(1,"Stop")

                               Else if isplaying and ispaused then
                               screen.addbutton(0,"Resume")
                               screen.addbutton(1,"Stop")
                               End if

                                'now add any non-conditional buttons

	    					screen.AddButton(2,"Network Schedule")
							screen.AddButton(3,"About CRN")
    						screen.AddButton(4,"Go Back")

                End function