Roku Developer Program

Join our online forum to talk to Roku developers and fellow channel creators. Ask questions, share tips with the community, and find helpful resources.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
360tv
Streaming Star

need help with a tiny piece of code editing an array.

so I have something like...


canvasItems = [
{
Text:"This is ImageCanvas 1"
TextAttrs:{Color:"#FFFFFFFF", Font:"Medium",
HAlign:"HCenter", VAlign:"VCenter",
Direction:"LeftToRight"}
TargetRect:{x:390,y:357,w:500,h:60}
},
{
Text:"This is ImageCanvas 2"
TextAttrs:{Color:"#FFFFFFFF", Font:"Medium",
HAlign:"HCenter", VAlign:"VCenter",
Direction:"LeftToRight"}
TargetRect:{x:390,y:357,w:500,h:60}
},
{
Text:"This is ImageCanvas 3"
TextAttrs:{Color:"#FFFFFFFF", Font:"Medium",
HAlign:"HCenter", VAlign:"VCenter",
Direction:"LeftToRight"}
TargetRect:{x:390,y:357,w:500,h:60}
}
]


I've previously been changing the text color by a roByteArray conversion
								
fadelevel = CreateObject("roByteArray")
fadelevel.fromhexstring(device.nextoverlayfontcolor)
fadelevel[0] = fadelevel[0] - 8 ' or whatever values.
canvasitems = [
Text:"This is ImageCanvas 3"
TextAttrs:{Color:"#" + fadelevel.tohexstring(), Font:"Medium",
HAlign:"HCenter", VAlign:"VCenter",
Direction:"LeftToRight"}
TargetRect:{x:390,y:357,w:500,h:60}
]
canvas.SetLayer(0, {Color:"#FF000000", CompositionMode:"Source"})
canvas.SetLayer(1, canvasItems)
canvas.Show()



And that worked fine for one canvas Item. My question is how do I roll thru an array of canvas items and change a value in all the TextAttrs nested Arrays?
0 Kudos
2 REPLIES 2
RokuMarkn
Visitor

Re: need help with a tiny piece of code editing an array.

If you just want to change the TextAttrs element you don't need to redefine all the other elements. You should be able to do something like this.

for each item in canvasitems
item.TextAttrs.Color = "#" + fadelevel.tohexstring()
end for
0 Kudos
360tv
Streaming Star

Re: need help with a tiny piece of code editing an array.

simple enough!
0 Kudos
Need Assistance?
Welcome to the Roku Community! Feel free to search our Community for answers or post your question to get help.

Become a Roku Streaming Expert!

Share your expertise, help fellow streamers, and unlock exclusive rewards as part of the Roku Community. Learn more.