PDA

View Full Version : Dynamically creating and anchoring controls



meathome
September 27th, 2013, 01:17
I am trying to create some controls from script, and it always says no vertical anchor defined, altough i have set a top and left anchor and anchored height and width



ctrl=createControl("stringcontrol","title_career1");
if ctrl then
ctrl.setAnchor("left","","left","absolute",15);
ctrl.setAnchor("top","","top","absolute",15);
ctrl.setAnchoredHeight(20);
ctrl.setAnchoredWidth(120);
ctrl.setReadOnly(true);
ctrl.setFont("sheetlabel");
ctrl.setValue(skillsWindow.career1.getValue());
end


So why I am missing a vertical anchor?

My second problem with dynamically created controls is with templates. I am trying to dynamically create a number of radio button groups. The idea was that I simply set the parameters value like I would set a table and then call the controls onInit to set it up like this



choices[1].setAnchor("left","","left","absolute",100);
choices[1].setAnchor("top","","top","absolute",15);
choices[1].setAnchoredHeight(20);
choices[1].parameters[1].font[1]="sheetlabelsmall";
choices[1].parameters[1].labels[1]="Test1|Test2|Test3";
choices[1].parameters[1].values[1]="Test1|Test2|Test3";
choices[1].parameters[1].optionwidth[1]=90;
choices[1].onInit();


Doesn't work at all and says parameters is a nil value so I tried setting it with choices[1]["parameters"]={} but that does not work either.. so how can I accomplish this?
Basically what I want is a list of radio button choices with labels and values based on a lua table (the length of the table defines how many choices there will be)

Edit:
I was able to fix the second problem simply by adding the needed properties to the template itself... and voila I was able to set them from script. Still no idea why I get the no vertical anchor defined for control x error.