I am trying to do a custom canvas. In doing so I want to present the user a back button. What I am having trouble with is returning a variable to tell the main function to clsoe. The variable in question is goBack. Basically. I define goBack as 0. I then track the users selection (0,1 or 2), pass it a function to make a decision to either play a video or close. If they chose the close button (selectedIndex 2) then change the variable goBack to be 1. However, it changes it in the subfunction (onOk) but inside showImageCanvas it is still 0.
function showImageCanvas(episodes, selectedEpisode, leftBread, rightBread)
episode = episodes[selectedEpisode]
goBack = 0
canvas = CreateObject("roImageCanvas")
port = CreateObject("roMessagePort")
posArray = GetPositions()
items = []
selectedIndex = 0
canvas.SetMessagePort(port)
canvasRect = canvas.GetCanvasRect()
'onOK(2)
'stop
items.Push({
url:"http://apache.303north.com/Roku/1280x165_overhang.png"
TargetRect: {x: 0, y: 0}
})
items.Push({
url:episode.hdposterurl
TargetRect: {x: 200, y: 200}
})
items.Push({
url:"pkg:/images/ptl-button-play.png"
TargetRect: posArray[0]
})
items.Push({
url:"pkg:/images/ptl-button-playall.png"
TargetRect: posArray[1]
})
items.Push({
url:"pkg:/images/ptl-button-back.png"
TargetRect: posArray[2]
})
items.Push({
Text:episode.description
TextAttrs:{Color:"#FFCCCCCC", Font:"Medium",
HAlign:"HCenter", VAlign:"VCenter",
Direction:"LeftToRight"}
TargetRect: {x: -50, y: 200}
})
ring = {
url: "pkg:/images/ptl-button-selection.png",
TargetRect: {x: posArray[selectedIndex].x-2, y: posArray[selectedIndex].y-2}
}
canvas.SetLayer(0, { Color: "#1d2535", CompositionMode: "Source" })
canvas.SetLayer(1, items)
canvas.SetLayer(2, ring)
canvas.Show()
while true
event = wait(0, port)
if (event<> invalid)
if (event.isRemoteKeyPressed())
index = event.GetIndex()
print selectedIndex
if (index = 4) OR (index = 2) 'Left or Up
selectedIndex = selectedIndex-1
if (selectedIndex < 0)
selectedIndex = 2
endif
else if (index = 5) OR (index = 3) 'Right or Down
selectedIndex = selectedIndex+1
if (selectedIndex > 2)
selectedIndex = 0
endif
else if (index = 6) 'OK
onOK(selectedIndex, episode, goBack)
print goBack
print "POST OK"
if goBack = 1
print "EXIT WHILE"
exit while
endif
print "END"
endif
ring.TargetRect = {x: posArray[selectedIndex].x-2, y: posArray[selectedIndex].y-2}
canvas.SetLayer(0, { Color: "#1d2535", CompositionMode: "Source" })
canvas.SetLayer(1, items)
canvas.SetLayer(2, ring)
endif
endif
end while
return selectedEpisode
End Function
function onOK(selectedIndex, episode, goBack)
screen = CreateObject("roVideoScreen")
screen.SetMessagePort(CreateObject("roMessagePort"))
screen.SetPositionNotificationPeriod(1)
screen.SetContent(episode)
print goBack
if selectedIndex = 0
print "Test 0"
episode.playStart = 0 ' Play
PlayVideo(episode)
else if selectedIndex = 1 ' Play All
print "Test 1"
PlayVideo(episode)
else if selectedIndex = 2 ' Back
print "Test 2"
goBack = 1
print goBack
end if
return goBack
end function
Function GetPositions() as object
posArray = []
posArray.Push({x: 500, y: 250})
posArray.Push({x: 500, y: 300})
posArray.Push({x: 500, y: 350})
return posArray
End Function