In hipjipp's example, because the variable assigned to the frame has been declared 'local', I would place it at the top of the *.lua file; that is, outside any other function declaration or whatever. That way it can be referenced by any function/variable in that lua file. But
only in that lua file.
If you declared it like this:
Code:
MinimapButton = CreateFrame('Button', "MainMenuBarToggler", Minimap);
then 'MinimapButton' would be a global variable and could effectively be seen by your and (technically) any other addon you were running in your current WoW session. In that case it actually wouldn't mater where you put the CreateFrame. It is a matter of what is called scope. Reading
this will give you a good idea.
As to the second part, you are correct in thinking you need an event to fire the :Load() method. Something like this:
Code:
MinimapButton:RegisterEvent("PLAYER_ENTERING_WORLD");
MinimapButton:SetScript("OnEvent", function (self, event, addon)
if(event == "PLAYER_ENTERING_WORLD") then
MinimapButton:Load();
MinimapButton:UnregisterEvent("PLAYER_ENTERING_WORLD");
OnEvent = nil;
end
end);
In the example above, you don't strictly need the conditional that checks for the type of event as there is only one registered, but you could have more events registered, in which case you would need a series of conditionals to allow the right code to fire from the appropriate event. Hope that helps.