Your first macro actually fails because
GetMouseFocus() does not return
ActionButton1Icon. It returns
ActionButton1.
GetMouseFocus() only returns the
top-most mouse-enabled frame. It doesn't return non-frame UI objects (like textures or font strings). It doesn't return frames that aren't mouse-enabled. And it only returns the mouse-enabled frame with the highest frame level/strata.
Since
ActionButton1Icon is a texture, not a frame, you won't get a pointer to it from
GetMouseFocus().
However, Seerah's solution won't work for your particular case, because
ActionButton1Icon is a child of what
GetMouseFocus() does return (
ActionButton1), not its backdrop. There isn't really a generic solution that will work to get all visible textures. If you're only interested in action button icon textures, the following would work:
/print _G[GetMouseFocus():GetName() .. "Icon"]:GetTexture()
Breaking that down:
- GetMouseFocus() returns the frame object.
- :GetName() returns the name of the object it's called on; in this case, the frame object.
- The string concatenation operator (..) appends "Icon" onto the end of the name.
- The table lookup in _G returns the object whose name in the global namespace matches the provided table key; in this case, a string consisting of the button's name with "Icon" on the end, which points to the texture object that serve's the button's icon.
- :GetTexture() returns the texture of the object it's called on.
Note that using this macro on objects that don't have a name will cause an error. Using it on objects that do have a name, but don't have a corresponding "nameIcon" object, will also cause an error.