touch problem

My function "Match" is not working with director,but it is working fine without director .Is there any other way to call a function when using Director?

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
for count = 1,4 do
        x = x + 200
        y = 20
 
        for insideCount = 1,3 do
                y = y + 200
 
                wordcover[totalButtons] = display.newImage("button.png");
                wordcover[totalButtons].x = x
                wordcover[totalButtons].y = y
                totalButtons = totalButtons + 1
 
                temp = math.random(1,#words)
                imgbtn[count] = display.newImage(words[temp] .. ".png");                                
 
                imgbtn[count].x = x
                imgbtn[count].y = y     
 
                imgbtn[count].myName = words[temp]
                imgbtn[count].number = totalButtons
 
                table.remove(words, temp)
 
                imgbtn[count]:addEventListener( "touch", imgbtn[count] )
                imgbtn[count].touch = match
                
        end
end
function match()
print ("Function is Working")
end

could you try

imgbtn[count]:addEventListener( "touch", match)

:)

Thanks for the reply.It worked but the problem now is that it is saying runtime error. Runtime error saying

1
2
3
Runtime error
   attempt to index local 'event' (a nil value)
stack traceback:

Your function match() is expecting 2 params to be passed into it, object and event. But I think only one is actually being passed in and that is event. Since you have object listed first, it gets set to the event value that is passed in and event doesn't get set to anything.

I think you have to change this so that event is the only param the function is expecting. Then look at event.target, event.id oe event.name , one of them may give you the object.number.

when you put this line

imgbtn[count]:addEventListener( "touch", match)

your function must be like

function myff(event)

end

and you can get target by event.target

:)

views:1321 update:2011/11/17 15:37:03
corona forums © 2003-2011