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

Observerfield -Multiple Firing

I think I saw a thread related to this but can't seem to locate it.  I have (1) observerfield instance that fires twice.  The observer is tied to "itemFocused" of a markupgrid. When scrolling the grid I have a print setup in debugger and can see that with each move the "onFocusChange"  is activated. Is this common practice or a bug of sometype?  I know there is only one observer setup. I set the observerfield just after setting the content of the grid. 
0 Kudos
8 REPLIES 8
EnTerr
Roku Guru

Re: Observerfield -Multiple Firing

Not sure what you are saying, maybe you should show minimal code example. Seems natural to me that with user moving selection/cursor with the remote - with each move the itemFocused would change and accordingly any observer of that would fire. The point is to be able to insert yourself into that if something has to be done.
0 Kudos
btpoole
Channel Surfer

Re: Observerfield -Multiple Firing

What I am saying is that for every one click of the remote to move the focus, it executes 2x.  For example focus starts on column 0 of grid. I press right button on remote, In debugger window the print statement appears 2x. Below is min code. Task runs in int, calls the setupcontnet, updatecontent from there. The setGridContent (not shown) loops thru and sets field values for grid. I set focus at end of updatecontent. Below code is result of debugger.

Sub init()
m.ContentTask_program = createObject("RoSGNode","ContentReader_Program")
m.ContentTask_program.ObserveField("ProgramContent", "setupcontent")
m.ContentTask_program.control = "RUN"
m.ProgramMarkupGrid.ObserveField("itemFocused", "onFocusChanged")
end sub

sub setupcontent()
m.programdata=m.ContentTask_program.ProgramContent.temp
updatecontent()
end sub

sub updatecontent()
m.ProgramMarkupGrid.content=setGridContent()
m.ProgramMarkupGrid.visible=true
m.ProgramMarkupGrid.SetFocus(true)
end sub

function onFocusChanged() as void
if m.ProgramMarkupGrid.visible=true
m.columnFocused=m.ProgramMarkupGrid.itemFocused MOD m.ProgramMarkupGrid.numColumns
  ?"PROGRAM COLUMN FOCUSED "m.columnFocused
end if
end function





DEBUGGER:

PROGRAM COLUMN FOCUSED  0
PROGRAM COLUMN FOCUSED  0
PROGRAM COLUMN FOCUSED  1
PROGRAM COLUMN FOCUSED  1
PROGRAM COLUMN FOCUSED  2
PROGRAM COLUMN FOCUSED  2
PROGRAM COLUMN FOCUSED  3
PROGRAM COLUMN FOCUSED  3


Grid starts on column 0, click right remote button moves to 1, then 2 then 3. Prints multiple times. 
0 Kudos
EnTerr
Roku Guru

Re: Observerfield -Multiple Firing

Ah yes, i also vaguely remember someone observing that before (but where?)

Out of curiosity - is this still the case if you observe via a port and not a field? I.e. `observeField()` with a port - and the run a loop listening on that either in main() or a task. That would help getting an idea if this is a bug (if only one msg hits the port, it's a bug - if there are two events fired, it may or may not be)
0 Kudos
btpoole
Channel Surfer

Re: Observerfield -Multiple Firing

Haven't yet but will try that and see where it leads.
Thanks for the suggestion.
0 Kudos
belltown
Roku Guru

Re: Observerfield -Multiple Firing

It might be worth putting a print statement in updateContent just to double-check that it is only getting called once, otherwise you'd have 2 field observers assigned. Out of curiosity, does the itemUnfocused event get called twice as well?
0 Kudos
btpoole
Channel Surfer

Re: Observerfield -Multiple Firing

belltown
I put print statement in the updatecontent function. It only shows up once. Also the "UN"focus also shows up twice.

DEBUGGER RESULT

IN SETSTATUS ************************************
IN GetAuthData
IN HOME
IN ENTRY INT
ENTER LOAD DATA. . .
IN REGISTRY TASK
IN SETMODE   
Registry CONTENT CREATE>>>>>>>>>>>>>>
CHANNEL LIST CONTENT CREATE>>>>>>>>>>>>>>
IN UPDATECONTENT STATUS 
IN ACTIVATIONSTATUS
in buildProgramArray 
PROGRAM GRID CONTENT CREAT>>>>>>>>>>>>>>
in setSlotContent
SLOTCONTENT>>> DONE
in setGridContent--
setGridContent DONE>>>>>>>>>>>>>>>>>>>>>>>>>>>>

PROGRAM COLUMN FOCUSED  0
PROGRAM COLUMN UN -1
UPDATACONTENT>>> DONE
PROGRAM COLUMN FOCUSED  0
PROGRAM COLUMN UN -1
PROGRAM COLUMN FOCUSED  1
PROGRAM COLUMN UN  0
PROGRAM COLUMN FOCUSED  1
PROGRAM COLUMN UN  0
PROGRAM COLUMN FOCUSED  2
PROGRAM COLUMN UN  1
PROGRAM COLUMN FOCUSED  2
PROGRAM COLUMN UN  1
0 Kudos
btpoole
Channel Surfer

Re: Observerfield -Multiple Firing

It seems also that I must press the remote button twice to get the code to continue. For instance, I press right arrow to scroll the gird, after the initial move if I press the right arrow or left arrow again, nothing happens, if I press a second time I get a response. Odd.
0 Kudos
a_kaftari
Reel Rookie

Re: Observerfield -Multiple Firing

0 Kudos
Need Assistance?
Welcome to the Roku Community! Feel free to search our Community for answers or post your question to get help.

Become a Roku Streaming Expert!

Share your expertise, help fellow streamers, and unlock exclusive rewards as part of the Roku Community. Learn more.