developer34
6 years agoChannel Surfer
BRIGHTSCRIPT: ERROR: roSGNode: Failed to create roSGNode with type LoginTask
this is my loginscreen.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>
this is my logintask.brs
sub init() m.top.functionName = "getURL" end sub Function getURL() url = CreateObject("roUrlTransfer") url.SetPort(CreateObject("roMessagePort")) url.SetUrl(m.global.api_url+"/access_path.php") rsp = url.AsyncPostFromString("checkUser=ObjectSol") event = wait(5000, url.GetPort()) if type(event) = "roUrlEvent" if event.GetResponseCode() = 200 response = ParseJson(event.GetString()) print response if response <> invalid if response.error_message <> invalid m.global.success_message = response.success_message m.global.data = response.data.ToStr() getToken() endif else m.top.msg = "Connection error" endif else m.top.msg = "Connection error" endif else if event = invalid m.top.msg = "Connection timeout" url.AsyncCancel() else m.top.msg = "Connection error" endif End Function Function getToken() sec = CreateObject("roRegistrySection", "Authentication") sec.Write("Username", m.top.username) sec.Write("Password", m.top.password) sec.Flush() url = CreateObject("roUrlTransfer") url.SetPort(CreateObject("roMessagePort")) url.SetUrl(m.global.data+"/stalker_portal/auth/token") url.AddHeader("Accept", "application/json") rsp = url.AsyncPostFromString("grant_type=password&username=" + m.top.username + "&password=" + m.top.password) event = wait(5000, url.GetPort()) if type(event) = "roUrlEvent" if event.GetResponseCode() = 200 response = ParseJson(event.GetString()) if response <> invalid if response.error <> invalid m.top.msg = response.error_description else if response.access_token <> invalid and response.user_id <> invalid m.global.token = response.access_token.Trim() m.global.user_id = response.user_id.ToStr() getVodCategories() endif else m.top.msg = "Connection error" endif else m.top.msg = "Connection error" endif else if event = invalid m.top.msg = "Connection timeout" url.AsyncCancel() else m.top.msg = "Connection error" endif End Function Function getVodCategories() cat = apiCall("video-categories") if cat <> invalid then m.global.vod_grp = cat getTVCategories() else m.top.msg = "Connection error" endif End Function Function getTVCategories() cat = apiCall("tv-genres") if cat <> invalid then m.global.tv_grp = cat m.top.msg = "OK" else m.top.msg = "Connection error" endif End Function
this is my logintask.xml
<?xml version="1.0" encoding="UTF-8"?> <component name="LoginTask" extends="Task"> <interface> <field id="content" type="node" /> <field id="username" type="string" /> <field id="password" type="string" /> <field id="token" type="string" /> <field id="user_id" type="string" /> <field id="msg" type="string" alwaysNotify="true" /> </interface> <script type="text/brightscript" uri = "pkg:/components/src/stalkerapiv2.brs"/> <script type="text/brightscript" uri = "pkg:/components/src/logintask.brs"/> </component>
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>
i am getting an error like this
BRIGHTSCRIPT: ERROR: roSGNode: Failed to create roSGNode with type LoginTask: pkg:/components/src/loginscreen.brs(2) BrightScript Micro Debugger. Enter any BrightScript statement, debug commands, or HELP. Suspending threads... Thread selected: 1* ...omponents/src/loginscreen.brs(3) m.LoginParser.observeField("msg", "returnMsg") Current Function: 001: sub init() 002: m.LoginParser = createObject("roSGNode","LoginTask") 003:* m.LoginParser.observeField("msg", "returnMsg") 004: m.top.backgroundURI = "pkg:/images/login_bg.png" 005: m.keyboard = m.top.findNode("keyboard") 006: m.fullkeyboard = m.top.findNode("fullkeyboard") 007: m.username = m.top.findNode("username") Interface not a member of BrightScript Component (runtime error &hf3) in pkg:/components/src/loginscreen.brs(3) 003: m.LoginParser.observeField("msg", "returnMsg") Backtrace: #0 Function init() As Void file/line: pkg:/components/src/loginscreen.brs(3) Local Variables: global Interface:ifGlobal m roAssociativeArray refcnt=2 count:3 Threads: ID Location Source Code 0 pkg:/source/main.brs(14) screen.show() 1* ...omponents/src/loginscreen.brs(3) m.LoginParser.observeField("msg", "returnMsg") *selected