Radio Like Buttons

Posted by Gigabook, Posted on January 28, 2012

0 votes

I was originally making this for an odesk project, but now that I realized how long it will take to perfect it, I will just update it as I go for everyone to use. It is like a check box. Here is how to use it so far:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
local control = require("control")
 
 newBox = control.newControl(
        {
        
        x = 100,
        y = 100,
        StrokeR = 0,
        StrokeG = 100,
        StrokeB = 100,
        StrokeWidth = 10,
        
        Size = 40,
        R = 255,
        G = 0,
        B = 0
        }
        )
        
 newBox1 = control.newControl(
        {
        
        x = 300,
        y = 300,
        StrokeR = 0,
        StrokeG = 100,
        StrokeB = 100,
        StrokeWidth = 10,
        
        Size = 70,
        R = 255,
        G = 0,
        B = 0
        }
        )
        
 
 
Here is the module:
 
 
 
 
module (..., package.seeall)
 
 
 
function newControl(b)
        local Group = display.newGroup()
        
        Group.Border = display.newRect(b.x, b.y, b.Size, b.Size)
        Group.Border:setFillColor(b.R, b.G, b.B)
        Group.Border.strokeWidth = b.StrokeWidth
        
        Group.Border:setStrokeColor(b.StrokeR, b.StrokeG, b.StrokeB)
 
function Group.checkit(event)
        if (event.phase == "began") then
                
        Group.Border:setFillColor(b.tapColorR, b.tapColorG, b.tapColorB)
 
 
end
end
 
        Group.Border:addEventListener("touch", Group.checkit)
        
        function Group.selected(event)
        if (event.phase == "began") then
                
                Group.isSelected = true
        end
        if (event.phase == "ended") then
                Group.isSelected = false
        end
        end
        
        Group.Border:addEventListener("touch", Group.selected)
return localGroup
 
end