WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   Lua/XML Help (https://www.wowinterface.com/forums/forumdisplay.php?f=16)
-   -   Can you name a frame AFTER it's been created? (https://www.wowinterface.com/forums/showthread.php?t=57363)

aallkkaa 08-16-19 03:28 PM

Can you name a frame AFTER it's been created?
 
I'm basically looking for a counterpart to frame:GetName()

I tried the following, which does not work:
Lua Code:
  1. frame = CreateFrame("Frame");
  2. frame:SetAttribute:"Name", "SomeName");

In cas you're wondering, I want to reuse a frame I use to listen to PLAYER_LOGIN as one of the configuration-dependent frames to create afterwards.

kurapica.igas 08-16-19 07:37 PM

No, you can't, there is no SetName method. But normally there is no need to give a frame name unless it's a secure one.

If you need access it in _G, just use _G[name] = frame, it's not a good practice, since you always can save it in your own addon.

Or you can create a parent-child system that the child's name is saved in its parent so you can access any frames in a root frame like `root.Form.Label:SetText(xx)`, it's the name of your own system, so you can change them to whatever you want.

aallkkaa 08-17-19 08:38 AM

Thank you for the awesome tips, kurapica.igas!

_G[name] = frame seems to be more what I wanted. But the parent-child system looks interesting. I'll play around with those.

Fizzlemizz 08-17-19 08:48 AM

The _G[] isn't required unless you're looking up the frame name as a string.

Code:

local f = Createframe("Frame", "FizzleFrameX", UIParent)
FizzleFrameX.Texture = FizzleFrameX:CreatTexture()


aallkkaa 08-17-19 10:57 AM

Quote:

Originally Posted by Fizzlemizz (Post 333252)
The _G[] isn't required unless you're looking up the frame name as a string.

Code:

local f = Createframe("Frame", "FizzleFrameX", UIParent)
FizzleFrameX.Texture = FizzleFrameX:CreateTexture()


(fixed a typo for you)
I'm not sure I understand what you said. I mean, in the example you gave, you could equally do:
Lua Code:
  1. local f = Createframe("Frame", "FizzleFrameX", UIParent)
  2. f.Texture = f:CreateTexture()
In any case, me wanting the frame to be globally accessible doesn't have anything to do with the addon's normal operation. It's a personal addon, whose frames' positions and geometries I may sometimes change in the code (which I haven't in a long time, but that's beyond the point). Instead of coding the changes in the addon and then reloading the UI to check it out, I like to do /run frame:SetPoint(...), /run frame:SetWidth(...), etc, right there on the console. That's it. ;)


All times are GMT -6. The time now is 11:43 PM.

vBulletin © 2020, Jelsoft Enterprises Ltd
© 2004 - 2020 MMOUI