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: 
developer34
Channel Surfer

BRIGHTSCRIPT: ERROR: roSGNode: Failed to create roSGNode with type LoginTask

This is my mainscene.brs

' ********** Copyright 2016 Roku Corp.  All Rights Reserved. **********  

sub init()
    m.top.SetFocus(true)
    m.top.backgroundURI = "pkg:/images/login_bg.png"
    m.loginBtn = m.top.findNode("loginBtn")
    m.loginscreen =  m.top.findNode("LoginScreen")
    m.loginscreen.observeField("ready", "onLoginReady")
End sub

 Function OnLoginReady()
    m.loginBtn.setFocus(true)
    m.loginscreen.visible = true
 end function 

This is my mainscene.xml

<?xml version="1.0" encoding="UTF-8"?>

<component name="MainScene" extends="Scene" initialFocus = "LoginScreen">
	<!-- importing main handler -->
    <script type="text/brightscript" uri="pkg:/components/src/MainScene.brs" />
    
    <children>
    	<LoginScreen id="LoginScreen"/>
    </children>
</component>

this is my loginsceen.brs

   sub init()
      m.LoginParser = createObject("roSGNode","LoginTask")
      m.LoginParser.observeField("msg", "returnMsg")
      m.top.backgroundURI = "pkg:/images/login_bg.png"
      m.keyboard = m.top.findNode("keyboard")
      m.fullkeyboard = m.top.findNode("fullkeyboard")
      m.username = m.top.findNode("username")
      m.usernameLabel = m.top.findNode("usernameLabel")
      m.password = m.top.findNode("password")
      m.passwordLabel = m.top.findNode("passwordLabel")
      m.loginBtn = m.top.findNode("loginBtn")
      m.loginBtn.observeField("buttonSelected", "btnSelected")
      m.loginLabel = m.top.findNode("btnLabel")
      m.loader = m.top.findNode("loader")
      m.loaderLabel = m.top.findNode("loaderLabel")
      m.urlfield = m.top.findNode("urlfield")
      m.keyboard.textEditBox.maxTextLength = 22
      
      m.username.text = m.global.username
      m.password.text = m.global.password
      
      m.username.cursorPosition = Len(m.username.text)
      m.password.cursorPosition = Len(m.password.text)
      
      m.backup = ""
      m.blocked = false
      m.top.setFocus(true)
    end sub

function onKeyEvent(key as String, press as Boolean) as Boolean
        
        if m.blocked then return true
   
        if m.loader.visible and ( key="up" or key="down" ) then m.loader.visible = false
               
        
        if m.fullkeyboard.visible then
            if m.username.active and (key = "OK" or key = "replay")  then
                m.username.text = m.keyboard.textEditBox.text
                m.username.cursorPosition = m.keyboard.textEditBox.cursorPosition
                return true
            else if m.password.active and (key = "OK" or key = "replay") then
                m.password.text = m.keyboard.textEditBox.text
                m.password.cursorPosition = m.keyboard.textEditBox.cursorPosition
                return true
            else if m.urlfield.active and (key = "OK" or key = "replay") then
                m.urlfield.text = m.keyboard.textEditBox.text
                m.urlfield.cursorPosition = m.keyboard.textEditBox.cursorPosition
                return true    
            else if key = "back" and m.username.active then
                m.backup = m.username.text
                m.fullkeyboard.visible = false
                m.keyboard.setFocus(false)
                m.username.setFocus(true)
                return true
            else if key = "back" and m.password.active then
                m.backup = m.password.text
                m.fullkeyboard.visible = false
                m.keyboard.setFocus(false)
                m.password.secureMode="true"
                m.password.setFocus(true)
                return true 
            else if key = "back" and m.urlfield.active then
                m.backup = m.urlfield.text
                m.fullkeyboard.visible = false
                m.keyboard.setFocus(false)
                m.urlfield.setFocus(true)
                return true     
            endif
            return true
        endif
        
        if key = "back" and press then
            m.top.goback = true
            return true
        endif
       
        if press then
            if key = "up" then
                if m.loginBtn.hasFocus() then
                   m.password.backgroundUri = "pkg:/images/text_field_on_hover.png"
                   m.password.active = true
                   m.username.active = false
                   m.loginBtn.setFocus(false)
                   m.password.setFocus(true)
                   m.backup = m.password.text
                   m.password.cursorPosition = Len(m.password.text)
                else if m.password.active then
                   m.password.active = false 
                   m.password.backgroundUri = "pkg:/images/text_field.png"    
                   m.username.backgroundUri = "pkg:/images/text_field_on_hover.png"
                   m.username.active = true
                   m.password.setFocus(false)
                   m.username.setFocus(true)
                   m.backup = m.username.text
                   m.username.cursorPosition = Len(m.username.text)
                   else if m.username.active then
                   m.username.active = false     
                   m.urlfield.backgroundUri = "pkg:/images/text_field_on_hover.png"
                   m.username.backgroundUri = "pkg:/images/text_field.png"
                   m.urlfield.active = true
                   m.username.setFocus(false)
                   m.urlfield.setFocus(true)
                   m.backup = m.urlfield.text
                   m.username.cursorPosition = Len(m.username.text)   
                endif
                
            else if key = "OK" then
                if m.username.active then
                    m.keyboard.textEditBox.text = m.username.text
                    m.keyboard.textEditBox.cursorPosition =  m.username.cursorPosition
                    m.keyboard.setFocus(true)
                    m.fullkeyboard.visible = true
                else if m.password.active then
                    m.password.secureMode = false
                    m.keyboard.textEditBox.text = m.password.text
                    m.keyboard.textEditBox.cursorPosition =  m.password.cursorPosition
                    m.keyboard.setFocus(true)
                    m.fullkeyboard.visible = true
                else if m.urlfield.active then
                    m.keyboard.textEditBox.text = m.urlfield.text
                    m.keyboard.textEditBox.cursorPosition =  m.urlfield.cursorPosition
                    m.keyboard.setFocus(true)
                    m.fullkeyboard.visible = true
                endif
            endif
           
           return true     
       endif
       
       if not press then     
            if key = "down" then
                 if m.password.active then
                    m.password.text = m.backup
                    m.password.active = "false"
                    m.password.backgroundUri = "pkg:/images/text_field.png"     
                    m.loginBtn.setFocus(true)
                 else if m.username.active then
                    m.username.text = m.backup
                    m.username.active = "false"     
                    m.username.setFocus(false)
                    m.password.active = "true"
                    m.password.setFocus(true)
                    m.password.backgroundUri = "pkg:/images/text_field_on_hover.png"
                    m.username.backgroundUri = "pkg:/images/text_field.png"
                    m.backup = m.password.text
                 else if m.urlfield.active then
                    m.urlfield.text = m.backup
                    m.urlfield.active = "false"     
                    m.urlfield.setFocus(false)
                    m.username.active = "true"
                    m.username.setFocus(true)
                    m.username.backgroundUri = "pkg:/images/text_field_on_hover.png"
                    m.urlfield.backgroundUri = "pkg:/images/text_field.png"
                    m.backup = m.username.text   
                 endif
            endif

        endif
        return true
end function

sub btnSelected()
    m.blocked = true
    if m.username.text = "" or m.password.text = "" then
        m.loader.color = "0xb40579FF"
        m.loaderLabel.color = "0xFFFFFFFF"
        m.loaderLabel.text = "Username or password is empty"
        m.blocked = false        
    else
        'm.registry.Write("username", m.username.text)
        'm.registry.Write("password", m.password.text)
        m.loader.color = "0xDDDDDD80"
        m.loaderLabel.color = "0x000000FF"
        m.loaderLabel.text = "Loading..."
        m.LoginParser.username = m.username.text
        m.LoginParser.password = m.password.text
        m.LoginParser.control = "RUN"
    endif
    m.loader.visible = true
end sub

sub returnMsg()
    m.loaderLabel.text = m.LoginParser.msg
    if m.LoginParser.msg <> "OK" then
        m.loader.color = "0xb40579FF"
        m.loaderLabel.color = "0xFFFFFFFF"
    else
        m.loader.visible = false
        m.top.visible = false
        m.top.ready = true
    endif
    m.blocked = false
endsub

this is my loginscreen.xml

<?xml version = "1.0" encoding = "utf-8" ?>
<component name="LoginScreen" extends = "Group" initialFocus = "loginBtn" >
<interface> 
  <field id="ready" type="bool" alwaysNotify="true" />
  <field id="goback" type="boolean" alwaysNotify="true" />
</interface>
<script type="text/brightscript" uri = "pkg:/components/src/loginscreen.brs"/>
  <children>
  <Group translation="[604,400]">
  	<Poster id="loginicon"
  	uri="pkg:/images/login_screen_logo.png"
  	width="500"
  	height="100"
  	translation="[8,-180]" />
	<TextEditBox id="urlfield" translation="[100,100]"  hintText="url" width="500" maxTextLength="24" backgroundUri="pkg:/images/text_field.png" hintTextColor="FAF7F6" />
    <TextEditBox id="username" translation="[100,204]" hintText="username" width="500" maxTextLength="24" backgroundUri="pkg:/images/text_field.png" hintTextColor="FAF7F6"/>
    <TextEditBox id="password" translation="[100,304]" hintText="password" width="500" maxTextLength="24" backgroundUri="pkg:/images/text_field.png" hintTextColor="FAF7F6" secureMode="true"/>
	<Poster id="urlicon"  translation="[50,110]" uri="pkg:/images/url_icon.png" width="30" height="55"/>
	<Poster id="usernameicon"  translation="[50,214]" uri="pkg:/images/username_icon.png" width="30" height="55"/>
	<Poster id="passwordicon"  translation="[50,314]" uri="pkg:/images/password_icon.png" width="30" height="55"/>
    <Button translation="[180,400]" id="loginBtn" showFocusFootprint="true" focusFootprintBitmapUri="pkg:/images/login_button.png" iconUri="" focusedIconUri="" height="90" focusBitmapUri="pkg:/images/login_button.png" minWidth="320" maxWidth="320">
    <Label id="btnLabel" color="0xFFFFFFFF" horizAlign="center" text="Login" width="320" height="90" numLines="1" vertAlign="center"/>
    </Button>
    </Group>
    <Rectangle
    	id = "fullkeyboard"    
  		color="0xb40579DD"
  		width="1416"
  		height="380"
  		translation="[252,680]" visible="false">
    <Keyboard id="keyboard" showTextEditBox="false" keyColor="0xFFFFFFFF"/>
    </Rectangle>
    <Rectangle
    	id="loader"   
  		color="0xDDDDDD80"
  		width="1920"
  		height="60"
  		translation="[0,1020]"
  		 visible="false">
  		<Label id="loaderLabel" color="0x000000FF" horizAlign="center" text="Loading..." width="1920" height="60" numLines="1" vertAlign="center"/>
  	</Rectangle>
  </children>
</component>
0 Kudos