-
Posted by zenasprime on Fri, 17 Jul 2009 20:47:20
I've been having some difficulties getting my frames to move. I was able to solve this issue with my last addon (WoWPedometer) but even with the same code added to my new addon I cannot get it moving. What am I doing wrong...
The relevant code can be found here.
Thanks,
-z
-
Posted by ALeX-L on Fri, 17 Jul 2009 21:03:47
As I know, this line already makes ur window movable :
<Frame name="WoWPUGBuilderFrame" toplevel="true" parent="UIParent" enableMouse="true" moveable="true" frameStrata="LOW">
U don't need to write extra code...
-
Posted by zenasprime on Fri, 17 Jul 2009 21:51:03
So, is the following unnecessary then?
<OnDragStart> self:StartMoving() </OnDragStart> <OnDragStop> self:StopMovingOrSizing() </OnDragStop>
and what about the .lua code?
function WoWPUGBuilder_OnLoad(frame) frame:RegisterForDrag("LeftButton") end
-
Posted by jnwhiteh on Sat, 18 Jul 2009 01:27:30
Making it movable is just a matter of enabling the movable flag. You need to set the script handlers. Troubleshooting:
- Check your Logs\FrameXML.log file to see if there are any errors.
- Alternatively, validate your file against the schema.
- Add a print statement to the load function to ensure it's being called.
- Add a print statement to the ondragstart function to ensure it's being called.
- Add a print statement to the ondragstop function to ensure it's being called.
Report back.
-
Posted by ALeX-L on Sun, 19 Jul 2009 15:59:13
Maybe I've made a mistake about extra code) try this in .xml. Without any functions in .lua
<OnLoad> this:RegisterForDrag("LeftButton"); </OnLoad> <OnDragStart> if(arg1 == "LeftButton") then this:StartMoving(); end </OnDragStart> <OnDragStop> this:StopMovingOrSizing(); </OnDragStop>
-
Posted by jnwhiteh on Sun, 19 Jul 2009 16:02:43
Maybe I've made a mistake about extra code) try this in .xml. Without any functions in .lua
<OnLoad> this:RegisterForDrag("LeftButton"); </OnLoad> <OnDragStart> if(arg1 == "LeftButton") then this:StartMoving(); end </OnDragStart> <OnDragStop> this:StopMovingOrSizing(); </OnDragStop>
You should be using self:RegisterForDrag("LeftButton"), although that might not be it. Actually there are a few issues in your code:
<OnLoad> self:RegisterForDrag("LeftButton"); </OnLoad> <OnDragStart> if(button == "LeftButton") then self:StartMoving(); end </OnDragStart> <OnDragStop> self:StopMovingOrSizing(); </OnDragStop>
-
Posted by zenasprime on Mon, 20 Jul 2009 14:39:55
From what I gather from the book, in chapter 12 it shows the following code for the combat tracker example as the only bits necessary to make a frame movable...
in the XML file...
add "movable="true"" attribute to
<Button>
add
<OnDragStart> self:StartMoving() </OnDragStart> <OnDragStop> self:StopMovingOrSizing() </OnDragStop>
and in the Lua file...
add to the OnLoad function...
frame:RegisterForDrag("LeftButton")
This code works fine for combat tracker. I've used the same code for my first addon WoWPedometer, though I remember it not working at first. I've used the same code for this new addon and it doesn't want to work.
I've gone and added
ChatFrame1:AddMessage("OnDragStart");
and
ChatFrame1:AddMessage("OnDragStop");
to the appropriate scripts... when I try to drag the frame I only get the "OnDragStop" message. It seems that self:StartMoving() is not being called.
The only difference I can see between my usage of this code in this addon and my previous one is that in my previous addon the frame was
<Button>
rather then<Frame>
.Could you try and run the code for my addon given in the link and let me know what you think might be getting screwed up?
Thanks, -z
-
Posted by ALeX-L on Mon, 20 Jul 2009 14:47:18
If u want to make a frame draggable why do u add an attribute to a button?
-
Posted by jnwhiteh on Mon, 20 Jul 2009 14:54:40
The problem is your OnLoad function is never being called. You should always add a simple "print" statement when debugging to check if that's the case.
<OnLoad function="WoWPUGBuilderFrame_OnLoad"/>
should be
<OnLoad function="WoWPUGBuilder_OnLoad"/>
-
Posted by jnwhiteh on Mon, 20 Jul 2009 14:55:21
If u want to make a frame draggable why do u add an attribute to a button?
That's not what he's doing. He said in the previous addon he was writing it was a button, and now he's trying to do the same thing to a frame and it's not working. He's completely right in that the code appears to be the same.. but there was a subtle error that was causing his code not to run.
-
Posted by zenasprime on Mon, 20 Jul 2009 17:07:59
Okay I got it. I not only fixed the OnLoad typo but also it appears that I spelled "movable" incorrectly. So as a result, I just took some time to drill into my skull the importance of using XML nanny. ;)
All is well now.
Thank you for the awesome assistance.
-z
-
Posted by jnwhiteh on Mon, 20 Jul 2009 18:13:22
Np, glad it worked out for you!