Confirmed bug. item.Update doesn't update the item.fileattr object.
We've fixed this for the next update.
If you need a workaround until then, you can either create a completely new Item for the file path, or use the item.attr or item.attr_text properties (which do get updated correctly, but are more fiddly if you want to test if a bit is set).
As an aside, the two Delay calls should not be needed. But one thing to note is that the initial item object uses cached values from the lister. If the lister hasn't reacted to the previous change yet, the attributes will be stale. That usually isn't worth worrying about, but might be if you want something which will work as a toggle even when clicked twice in quick succession, or immediately after something else has changed the attributes. You can work around that (once the fix is out) by calling item.Update right after obtaining the object:
function OnClick(clickData)
{
// --------------------------------------------------------
var item = clickData.func.sourcetab.files(0); // or selected(0);
item.Update(); // item contains cached data from the lister, ensure it's up to date
DOpus.output("item.fileattr.r (before) = "+item.fileattr.r); // Initial state
var f = item.Open("m");
var str = (item.fileattr.r) ? "-r" : "+r";
f.setattr(str); // Toggle current archive attribute
f.Close();
item.Update();
DOpus.output("item.fileattr.r (after) = "+item.fileattr.r); // State after toggle
// --------------------------------------------------------
}
I also added the f.Close(); line for good measure, although it's not really required for the current code.
Also changed item.Open("mef"); to just item.Open("m");, as it seemed more correct, at least for the current code.