Your Digital Media Has Never Looked So Good

Topic Author
Posts: 30
Joined: Tue Aug 14, 2018 8:18 am

Dynamically creating contentNodes for LabelList

Tue Oct 09, 2018 12:33 pm

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:

          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" />


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 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!
Posts: 9
Joined: Fri Oct 26, 2018 5:33 am

Re: Dynamically creating contentNodes for LabelList

Fri Oct 26, 2018 7:04 am

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.
Posts: 99
Joined: Thu Apr 13, 2017 11:00 pm

Re: Dynamically creating contentNodes for LabelList

Sat Oct 27, 2018 9:17 am

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

 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" />
User avatar
Posts: 312
Joined: Wed Sep 10, 2014 10:44 am
Location: Roku HQ

Re: Dynamically creating contentNodes for LabelList

Mon Oct 29, 2018 4:50 pm

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.

Who is online

Users browsing this forum: No registered users and 6 guests