It does indeed work as it was designed to work. You are assuming that clicking a button makes it the active layout object. This is not the case and if it was the case, many layout designs would fail to work correctly.
Say you have a text field with edit buttons intended to modify text either selected or at the insertion point marked by the cursor. If clicking a button made it the active layout object, the text field would lose that focus (selected text and or cursor position) and the scripts performed by those buttons would fail to work as intended.
Then the online documentation should be updated to say what you just said.
You could post to Feedback or use Report an Issue to report this as a "documentation bug" if you wish.
But when I check the documentation in FileMaker Help, if find that it states:
Returns the object name of the active layout object in the calculation's current window; otherwise, returns an empty string.
That would seem a fully accurate description of what the function does. I haven't found an entry that says clicking a button makes it an active layout object--which would definitely need correcting if such exists.
You can, BTW, make the button an active layout object by using Go to Object in a script or by pressing tab if the button is the next object in the tab order--just not by clicking it.
But here's where it get confusing. Filemaker help goes on to say::
There is a named button on the current layout called cancelButton. When the focus is on the button, Get(ActiveLayoutObjectName) returns cancelButton.
And that's completely correct. You just can't click the button to put the focus on it. You'd press tab/return/enter to move the focus to the button and then only if the button object is in the tab order. Or a script can put the focus on the button with Go to Object.
But I agree that using a button object in the example without further explanation is just asking for confusion on the part of new users who read that help article.
I happen to have a link to someone responsible for the online help and can drop them a line pointing out this source of confusion.
The person I emailed, agrees that this issue needs to be modified in future releases and has logged it accordingly.
Thanks for your help. You have shed new light on this topic that is greatly appreciated.