Label Node Created in main.brs not rendering

I am creating a label in my main.brs with CreateObject, which I thought would be fairly simple. However, it is not rendering, and I have no idea why.

This happens within a function where I create a VideoNode via CreateObject, and that seems to show up fine.

My code is:

label = CreateObject("roSGNode", "Label")
  label.text = "EPISODES AVAILABLE"
  label.translation="[50, 50]"
  label.numlines="1"
  label.color="0xFFFFFF"
  label.id = "episodeslabel"

If I print label, I get this, which looks correct to me, but it just doesn’t appear anywhere on the screen (as if visibility were false)! What am I missing?!

<Component: roSGNode:Label> =
{
    color: -1
    displayPartialLines: false
    ellipsisText: ""
    ellipsizeOnBoundary: false
    font: <Component: roSGNode:Font>
    height: 0
    horizAlign: "left"
    isTextEllipsized: false
    lineSpacing: 8
    maxLines: 0
    numLines: 1
    text: "EPISODES AVAILABLE"
    truncateOnDelimiter: ""
    vertAlign: "top"
    width: 0
    wordBreakChars: ""
    wrap: false
    childRenderOrder: "last"
    clippingRect: <Component: roAssociativeArray>
    enableRenderTracking: false
    inheritParentOpacity: true
    inheritParentTransform: true
    muteAudioGuide: false
    opacity: 1
    renderPass: 0
    renderTracking: "disabled"
    rotation: 0
    scale: <Component: roArray>
    scaleRotateCenter: <Component: roArray>
    translation: <Component: roArray>
    visible: true
    change: <Component: roAssociativeArray>
    focusable: false
    focusedChild: <Component: roInvalid>
    id: "episodeslabel"
}

I’d guess the color should be in this format “0x000000”.

color: -1

Yeah, I’m not sure why that prints like that. In my brs I specify


label.color="0xFFFFFF"

I think you need to add the label to the current view as a child object. Use findNode() to get the node to which you wish to add the child. Then use appendChild(). Reference here: Reference

Here’s another way using createChild():

m.grid = m.top.findNode("gridRowList")
m.fade = m.grid.CreateChild("MaskGroup")
    m.fade.setFields({
            id: "fadeMaskGroup"
            maskuri: "pkg:/images/fade_3_sides.png"
            masksize: "[1280,720]"
            maskOffset: "[0,0]"
    })  

For some reason that throws a fatal error. I have:


row = [i]createObject[/i]("RoSGNode","VideoNode")
label = [i]CreateObject[/i]("roSGNode", "Label")
label.[b]text[/b] = "EPISODES AVAILABLE"
row.appendChild(label)

I’m not sure why that crashes things-- it doesn’t seem that unusual to me..

For some reason that throws a fatal error. I have:


row = createObject("RoSGNode","VideoNode")
label = CreateObject("roSGNode", "Label")
label.text = "EPISODES AVAILABLE"
row.appendChild(label)

I’m not sure why that crashes things-- it doesn’t seem that unusual to me..

I tried reworking this a little, annd now I’m getting a Type mismatch error (appending a Label Node as a child to a VideoNode). Is that prohibited for some reason?

I think you meant to put “video” instead of “VideoNode” (video)

Sorry for being vague. I’ve just tried this in my videoview.brs and it worked for me. (I’m using SGDEX)

video = m.top.createChild("Video")
    video.id = "video"
    video.width = "1280"
    video.height = "720"
    video.translation = "[0,0]"
    video.enableUI = "false"
    video.disableScreenSaver = m.top.disableScreenSaver

    'Set m.video before setting theme as theme require m.video to be populated
    m.video = video

    if m.LastThemeAttributes <> Invalid then
        SGDEX_SetTheme(m.LastThemeAttributes)
    end if

    video.ObserveFieldScoped("position", "OnPositionChanged")
    video.ObserveFieldScoped("duration", "OnDurationChanged")
    video.ObserveFieldScoped("state", "OnVideoStateChanged")

label = CreateObject("roSGNode", "Label")
label.text = "EPISODES AVAILABLE"
video.appendChild(label)

If you’re starting a channel from scratch I recommend the SGDEX Componentsand one of the SGDEX sample channels to get started.

you can’t create a visual node before you initialize your scenegraph scene; unless you want all h e l l to break loose (crashing/hanging/cats loving dogs, end of the world scenarios).