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

Dynamically creating contentNodes for LabelList

I'm very new to Roku development, so please pardon my ignorance.

I have an array of strings and I'm trying to dynamically create a LabelList by looping through this array and setting each value as a ContentNode within the LabelList. However, I think I'm having a problem setting the LabelList as the "parent" of these contentNodes--ie, I'm essentially creating an empty LabelList.

My code is:




/* below, 'arr' is my associative array */
genreList = [i]createObject[/i]("RoSGNode","LabelList")
ContentNode_object = [i]createObject[/i]("RoSGNode","ContentNode")
   [b]for[/b] [b]each[/b] key [b]in[/b] arr
     ContentNode_child_object = ContentNode_object.createChild("ContentNode")
     ContentNode_child_object.field_name = arr[key]
   end for



Ideally, this would output the equivalent of this XML:

<LabelList
          id = "GenreList"
          translation = "[160,92]"
          itemSize = "[440,48]" >
 
          <ContentNode id = "genremenucontent" role = "content" >
           <ContentNode title = "sports" />
           <ContentNode title = "music" />
           <ContentNode title = "history" />
           <ContentNode title = "documentaries" />
    
          </ContentNode>

        </LabelList>


If I print LabelList, just to see what it is, I get the following, which makes me think the child ContentNode is not getting set correctly. 



<Component: roSGNode:LabelList> =
{
    color: -572662273
    focusedColor: 640034559
    focusedFont: <Component: roSGNode:Font>
    font: <Component: roSGNode:Font>
    textHorizAlign: "left"
    textVertAlign: "top"
    animateToItem: -1
    columnSpacings: <Component: roArray>
    columnWidths: <Component: roArray>
    content: <Component: roInvalid>
    currFocusColumn: -1
    currFocusFeedbackOpacity: 1
    currFocusRow: -1
    currFocusSection: -1
    drawFocusFeedback: true
    drawFocusFeedbackOnTop: false
    fadeFocusFeedbackWhenAutoScrolling: false
    fixedLayout: false
    focusBitmapBlendColor: -1
    focusBitmapUri: ""
    focusColumn: <Component: roArray>
    focusFootprintBitmapUri: ""
    focusFootprintBlendColor: -1
    focusRow: <Component: roArray>
    horizFocusAnimationStyle: "floatingfocus"
    horizFocusDirection: "none"
    itemClippingRect: <Component: roAssociativeArray>
    itemFocused: -1
    itemSelected: -1
    itemSize: <Component: roArray>
    itemSpacing: <Component: roArray>
    itemUnfocused: -1
    jumpToItem: -1
    numColumns: 1
    numRenderPasses: 3
    numRows: 12
    rowHeights: <Component: roArray>
    rowSpacings: <Component: roArray>
    scrollingStatus: false
    sectionDividerBitmapUri: ""
    sectionDividerFont: <Component: roSGNode:Font>
    sectionDividerHeight: 40
    sectionDividerLeftOffset: 0
    sectionDividerMinWidth: 117
    sectionDividerSpacing: 10
    sectionDividerTextColor: -572662273
    sectionDividerTopOffset: 0
    sectionDividerWidth: 0
    vertFocusAnimationStyle: "fixedfocuswrap"
    vertFocusDirection: "none"
    wrapDividerBitmapUri: ""
    wrapDividerHeight: 24
    wrapDividerLeftOffset: 0
    wrapDividerWidth: 0
    childRenderOrder: "last"
    clippingRect: <Component: roAssociativeArray>
    enableRenderTracking: true
    inheritParentOpacity: true
    inheritParentTransform: true
    muteAudioGuide: false
    opacity: 1
    renderPass: 0
    renderTracking: "none"
    rotation: 0
    scale: <Component: roArray>
    scaleRotateCenter: <Component: roArray>
    translation: <Component: roArray>
    visible: true
    change: <Component: roAssociativeArray>
    focusable: true
    focusedChild: <Component: roInvalid>
    id: ""
}


I found this post https://sdkdocs.roku.com/display/sdkdoc/Downloading+Server+Content on using a Task Node that seemed to be a similar case of what I need to do, but I think it's overcomplicated for my use case-- I don't need to download any information, as I already have this.

Any help or guidance would be greatly appreciated!
0 Kudos
4 REPLIES 4
sdpetersen
Visitor

Re: Dynamically creating contentNodes for LabelList

Have you had any success figuring this out? I think I'm running into a similar issue and was hoping for any insight you can share.
0 Kudos
norcaljohnny
Roku Guru

Re: Dynamically creating contentNodes for LabelList

Do you realize you can actually use your mark up in the xml component and disregard the rest of your code..

<LabelList
 id = "GenreList"
 translation = "[160,92]"
 itemSize = "[440,48]" >
  <ContentNode id = "genremenucontent" role = "content" >
   <ContentNode title = "sports" />
   <ContentNode title = "music" />
   <ContentNode title = "history" />
   <ContentNode title = "documentaries" />
</ContentNode>
</LabelList>
RokuKC
Roku Employee
Roku Employee

Re: Dynamically creating contentNodes for LabelList

"lisakb140" wrote:
...
My code is:


genreList = createObject("RoSGNode","LabelList")
ContentNode_object = createObject("RoSGNode","ContentNode")
for each key in arr
     ContentNode_child_object = ContentNode_object.createChild("ContentNode")
     ContentNode_child_object.field_name = arr[key]
end for



There seem to be 2 problems there.

First is that after creating the content it needs to be associated with the LabelList, e.g. by assigning the newly created ContentNode to the LabelList's content field.

genreList.content = ContentNode_object


Second, maybe just a problem with the example code, but assigning to .field_name won't do anything useful.

If your arr was something like ["Sports", "Music", "History", "Documentaries"] you could do:

   ContentNode_child_object.title = key

in the loop which I expect works to add a list of buttons to the LabelList.
Possum
Channel Surfer

Re: Dynamically creating contentNodes for LabelList

genreList.content = ContentNode_object

Disregarding the second issue I wanted to emphasize how the above line of code effectively solved the issue for me as well.

If you are looking to populate a list, such as a CheckList or perhaps a RadioButtonList, and nothing is showing up this very well could be the issue. 

Thank you Roku Employee for pointing this obscure nomenclature out.  I thought createChild or appendChild would have been the answer, but I was 100% wrong.

I just spent 12 hours trying to figure this out.  Used every trick in the book.  Very frustrating.  The lack of programming usable Brightscript documentation (and worth while examples) certainly is a limiting factor on the number of programmers creating for Roku and  it really needs to be addressed.

0 Kudos