Ok, it appears that setting the layer of a frame from within another frame has issues.
Code:
Code for RiftAddon.toc
Identifier = "kTest"
Name = "Karuul's Testing System"
Description = "Simple Test Addon"
Author = "Karuul"
Website = ""
Email = "Unknown@gmail.com"
Version = "0.01"
Environment = "1.5"
RunOnStartup = {
"main.lua"
}
Code for main.lua
kTest = {}
kTest.context = UI.CreateContext("kTest")
function kTest.main()
red = UI.CreateFrame("Frame", "Red", kTest.context)
red:SetWidth(40)
red:SetHeight(40)
red:SetPoint ("CENTER", UIParent, "CENTER",0,-10)
red:SetBackgroundColor(1, 0, 0)
red:SetLayer(1)
red:SetVisible(true)
green = UI.CreateFrame("Frame", "Green", kTest.context)
green:SetWidth(40)
green:SetHeight(40)
green:SetPoint ("CENTER", UIParent, "CENTER",0,10)
green:SetBackgroundColor(0, 1, 0)
green:SetLayer(2)
green:SetVisible(true)
button = UI.CreateFrame("RiftButton", "Button", kTest.context)
button:SetText("Switch")
button:SetWidth(100)
button:SetHeight(40)
button:SetPoint ("CENTER", UIParent, "CENTER",0,60)
button:SetVisible(true)
function button.Event:LeftPress()
if red:GetLayer() == 1 then
red:SetLayer(3)
else
red:SetLayer(1)
end
print("Set Red to layer " .. tostring(red:GetLayer()))
print("Green is layer " .. tostring(green:GetLayer()))
end
end
function kTest.commandHandler(commandline)
red:SetLayer(red:GetLayer())
end
table.insert(Command.Slash.Register("kTest"), {kTest.commandHandler, "kTest", "config"})
kTest.main()
When you load the sample addon you will see a red box, a green box that overlaps the red box and a button below them. To start red is set to layer 1 and green is set to layer 2.
Clicking the button will change the layer of the red box and print out the layer of the red box and the green box. You will see that every time you click the button the Red layer changes but the screen does not update and the two boxes stay how they are.
If you then run the /ktest command you will see the boxes update. So if Red was 3 and Green was 2 the Red will be on top and likewise if Red was 1 and Green was 2 Green would be on top.
As you can see all the /ktest command does is red:SetLayer(red:GetLayer())
Bookmarks