Bidmaron
May 10th, 2009, 02:17
For those who code FG2, can I get you to take a look at the simple extension below and determine why the button isn't working right? Since I could never get an answer before when I asked more than one question, I'm keeping it to just this one question now: Why does the button graphic vanish when the button is pushed? What is supposed to happen is that when you click the button, the button down graphic replaces the original graphic and then when you let up the mouse button, the original button up graphic returns. Instead, the button graphic vanishes and neither the button down nor the button up is there. The button textwidget "Test" remains, however. If the console window is up, you will see the OnClick function printing out "clicked" when you let the button go. If you click it again after the graphic is gone, the onClick fires again, printing "clicked" into the console window. What am I doing wrong? Here is the code:
<?xml version="1.0" encoding="iso-8859-1"?>
<root version="2.0">
<properties>
<name>Programming Tools</name>
<version>1</version>
<author>Bidmaron</author>
<description>An extension with programming utilities.</description>
</properties>
<base>
<icon name="gears" file="Programming.png" />
<icon name="butn" file="button.png" />
<icon name="butn_down" file="button_down.png" />
<template name="framebutton">
<genericcontrol>
<icon>butn</icon>
<script>
function onClickDown(button,x,y)
if button == 1 then
setIcon(butn_down);
return true;
end
end
function onClickRelease(button,x,y)
if button == 1 then
setIcon(butn);
if self.onClicked then
print("have self");
self.onClicked();
else
print("no self");
end
bringToFront();
return true;
end
end
function onInit()
if label then
widget=addTextWidget("sheetlabelsmallbold",label[1]);
else
widget=addTextWidget("sheetlabelsmallbold","Okay");
end
widget.setPosition("center",0,1);
end
</script>
</genericcontrol>
</template>
<windowclass name="programlist">
<frame>storybox</frame>
<dynamic />
<datasource>debug</datasource>
<placement>
<size>
<width>275</width>
<height>350</height>
</size>
</placement>
<sizelimits>
<dynamic />
<minimum>
<width>200</width>
<height>220</height>
</minimum>
</sizelimits>
<nodelete />
<sheetdata>
<stringcontrol name="flagger">
<bounds>22,18,-22,38</bounds>
<disable />
<empty>Window Title</empty>
<nodrag />
<nodrop />
<nodragselect />
</stringcontrol>
<framebutton name="test">
<label>Test</label>
<noanchor>render</noanchor>
<bounds>-66,-42,46,27</bounds>
<script>
function onClicked()
print("clicked");
end
</script>
</framebutton>
</sheetdata>
</windowclass>
<script name="programminginit">
function onInit()
if not User.isLocal() and User.isHost() then
if DB.findNode("debug") then
DesktopManager.registerDockShortcut("gears", "gears", "Programming", "programlist", " ");
end
end
end
</script>
</base>
</root>
Attached are graphics showing the window before the first click and then the window after the first click:
<?xml version="1.0" encoding="iso-8859-1"?>
<root version="2.0">
<properties>
<name>Programming Tools</name>
<version>1</version>
<author>Bidmaron</author>
<description>An extension with programming utilities.</description>
</properties>
<base>
<icon name="gears" file="Programming.png" />
<icon name="butn" file="button.png" />
<icon name="butn_down" file="button_down.png" />
<template name="framebutton">
<genericcontrol>
<icon>butn</icon>
<script>
function onClickDown(button,x,y)
if button == 1 then
setIcon(butn_down);
return true;
end
end
function onClickRelease(button,x,y)
if button == 1 then
setIcon(butn);
if self.onClicked then
print("have self");
self.onClicked();
else
print("no self");
end
bringToFront();
return true;
end
end
function onInit()
if label then
widget=addTextWidget("sheetlabelsmallbold",label[1]);
else
widget=addTextWidget("sheetlabelsmallbold","Okay");
end
widget.setPosition("center",0,1);
end
</script>
</genericcontrol>
</template>
<windowclass name="programlist">
<frame>storybox</frame>
<dynamic />
<datasource>debug</datasource>
<placement>
<size>
<width>275</width>
<height>350</height>
</size>
</placement>
<sizelimits>
<dynamic />
<minimum>
<width>200</width>
<height>220</height>
</minimum>
</sizelimits>
<nodelete />
<sheetdata>
<stringcontrol name="flagger">
<bounds>22,18,-22,38</bounds>
<disable />
<empty>Window Title</empty>
<nodrag />
<nodrop />
<nodragselect />
</stringcontrol>
<framebutton name="test">
<label>Test</label>
<noanchor>render</noanchor>
<bounds>-66,-42,46,27</bounds>
<script>
function onClicked()
print("clicked");
end
</script>
</framebutton>
</sheetdata>
</windowclass>
<script name="programminginit">
function onInit()
if not User.isLocal() and User.isHost() then
if DB.findNode("debug") then
DesktopManager.registerDockShortcut("gears", "gears", "Programming", "programlist", " ");
end
end
end
</script>
</base>
</root>
Attached are graphics showing the window before the first click and then the window after the first click: