View Single Post
10-08-15, 04:12 PM   #2
sticklord
A Wyrmkin Dreamwalker
AddOn Author - Click to view addons
Join Date: Aug 2014
Posts: 57
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:
  1. local myFrame = CreateFrame("Frame","Frame_Name",UIParent,"ButtonFrameTemplate")
  2. myFrame:SetSize(255,200)
  3. myFrame:ClearAllPoints()
  4. myFrame:SetPoint("LEFT",75,75)
  5. myFrame:EnableMouse(true)
  6. myFrame:SetMovable(true)
  7. myFrame:RegisterForDrag("LeftButton")
  8. myFrame:SetScript("OnDragStart",myFrame.StartMoving)
  9. myFrame:SetScript("OnDragStop",myFrame.StopMovingOrSizing)
  10. myFrame.unit = "player"
  11.  
  12. local img1 = myFrame:CreateTexture(nil, "ARTWORK")
  13. img1:SetHeight(60)
  14. img1:SetWidth(60)
  15. img1:SetPoint("TOPLEFT", -6, 8)
  16.  
  17. myFrame:RegisterEvent("UNIT_PORTRAIT_UPDATE")
  18. myFrame:SetScript('OnEvent', function(self, event, ...)
  19.     if (event == "UNIT_PORTRAIT_UPDATE") then
  20.         local unit = ...
  21.         if (unit == self.unit) then
  22.             SetPortraitTexture(img1, self.unit)
  23.         end
  24.     end
  25. end)

Last edited by sticklord : 10-08-15 at 04:21 PM.
  Reply With Quote