Forum Discussion

bmceldowney's avatar
9 years ago

Is there a way to get the currently focused node?

I'm wondering if there is a reliable way to get a reference to the currently focused node. I'm familiar with observing the focusedChild property, but that only gets me the immediate child in the focus chain. I'd prefer to be able to do something along these lines:
sub init()
    m.top.observeField("focusedChild", "focusChanged")
end sub

sub focusChanged(evt)
    if m.top.isInFocusChain()
        child = evt.getData()
        while true
            if type(child.focusedChild) = "roInvalid" then exit while
            child = child.focusedChild
        end while

        'do some stuff with the focused node
    end if
end sub


But according to the focusedChild documentation:

Accessing the value of the field will result in script errors.

Is there a way to get the node that actually has focus?

12 Replies