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: 
brocker
Visitor

roAssociativeArray Logic

Hopefully a quick question. I'm trying to learn about the roAssociativeArray, and created the following, but am getting an error "Member function not found in BrightScript Component or interface."

Why doesn't this work ( I copied basic syntax from a previous demo )?

Sub Main()
Web = SetAssociativeArray()
Web.ThisIsOne()
End Sub

Function SetAssociativeArray() As Object
Print "Set Array"
Web = CreateObject("roAssociativeArray")
Web.ThisIsOne = One
Web.ThisIsTwo = Two
End Function

Sub One()
Print "Hit One"
End Sub

Sub Two()
Print "Hit Two"
End Sub


A demo project does something similar, and it compiles, so not sure what my issue is? Any advice?

Thanks
Bud
0 Kudos
5 REPLIES 5
TheEndless
Channel Surfer

Re: roAssociativeArray Logic

Your SetAssociativeArray function never returns an object. Add a "Return Web" to the end of it, and you should be in business.
My Channels: http://roku.permanence.com - Twitter: @TheEndlessDev
Instant Watch Browser (NetflixIWB), Aquarium Screensaver (AQUARIUM), Clever Clocks Screensaver (CLEVERCLOCKS), iTunes Podcasts (ITPC), My Channels (MYCHANNELS)
0 Kudos
brocker
Visitor

Re: roAssociativeArray Logic

Jeeze, man what a silly mistake. Worked like a charm.

Thanks Endless, you are the best.

Regards
Bud
0 Kudos
TheEndless
Channel Surfer

Re: roAssociativeArray Logic

Sure thing.. it may also be worth noting that your SetAssociativeArray function can be written using a different syntax that you might find preferable:
Function SetAssociativeArray() As Object
Web = {
ThisIsOne: One
ThisIsTwo: Two
}
Return Web
End Function
My Channels: http://roku.permanence.com - Twitter: @TheEndlessDev
Instant Watch Browser (NetflixIWB), Aquarium Screensaver (AQUARIUM), Clever Clocks Screensaver (CLEVERCLOCKS), iTunes Podcasts (ITPC), My Channels (MYCHANNELS)
0 Kudos
brocker
Visitor

Re: roAssociativeArray Logic

Cool! That does read very nice. I've seen that in the reference guide, but hadn't spent any time reading about it.

To be sure, it still creates a AssociativeArray, but I just don't have to declare it with "CreateObject" like in my earlier code block?

Best
Bud
0 Kudos
renojim
Community Streaming Expert

Re: roAssociativeArray Logic

Correct. Another shortcut for creating an roAssociativeArray is this syntax:
Web = {} ' creates empty roAssociativeArray 
Web.ThisIsOne = One
Web.ThisIsTwo = Two

-JT
Roku Community Streaming Expert

Help others find this answer and click "Accept as Solution."
If you appreciate my answer, maybe give me a Kudo.

I am not a Roku employee.
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.