InputField = class() -- a class I use to enter input variables
function InputField:init(name,x,y,init_value)
self.name = name
self.x = x
self.y = y
self.editor = D2Editor.newRichText()
self.editor:move(x+30,y)
self.editor:resize(100,28)
self.editor:setBorder(1)
self.editor:setText(var.recall(name) or (init_value or 0)) -- initially store at construction time: init_value (if defined) or 0 (if not defined) or already stored variable value (if the page is re-entered)
var.store(name,self.editor:getText())
end
...
function InputField:storeVariable() -- called by clients like on.loseFocus() function
var.store(self.name,self.editor:getText())
end
...
function on.construction() -- create "objects"
...
field = {}
field[1] = InputField('er',2,4)
field[2] = InputField('ev',2,34)
...
end
function on.getFocus()
field[1]:setFocus()
end
function on.loseFocus()
for i = 1, #field do
field:storeVariable()
end
end