I guess you mean it all works, but the SetPortraitTexture() doesn't add the player to the portrait on first startup? If so it might be because for some reason you can't get the texture at startup. Try to delay the creation abit i.e:
Code:
local ADDON_NAME, ns = ...
local f = CreateFrame("Frame")
f:RegisterEvent("ADDON_LOADED")
f:SetScript("OnEvent", function(self, event, ...)
if (ADDON_NAME == ...) then
-- Code here
end
end)
Wait i changed my mind. Use this instead:
Lua Code:
local myFrame = CreateFrame("Frame","Frame_Name",UIParent,"ButtonFrameTemplate")
myFrame:SetSize(255,200)
myFrame:ClearAllPoints()
myFrame:SetPoint("LEFT",75,75)
myFrame:EnableMouse(true)
myFrame:SetMovable(true)
myFrame:RegisterForDrag("LeftButton")
myFrame:SetScript("OnDragStart",myFrame.StartMoving)
myFrame:SetScript("OnDragStop",myFrame.StopMovingOrSizing)
myFrame.unit = "player"
local img1 = myFrame:CreateTexture(nil, "ARTWORK")
img1:SetHeight(60)
img1:SetWidth(60)
img1:SetPoint("TOPLEFT", -6, 8)
myFrame:RegisterEvent("UNIT_PORTRAIT_UPDATE")
myFrame:SetScript('OnEvent', function(self, event, ...)
if (event == "UNIT_PORTRAIT_UPDATE") then
local unit = ...
if (unit == self.unit) then
SetPortraitTexture(img1, self.unit)
end
end
end)