Dragging many objects in a table. [Solved]

If anybody was wondering how to do the thing I was trying to accomplish heres a good example…

[lua]display.setStatusBar( display.HiddenStatusBar ) – HIDE STATUS BAR

local gameState = 0

local _W = display.contentWidth
local _H = display.contentHeight

local gBox = display.newRect(0,0,50,50)
gBox.x = math.random(150,200) ; gBox.y = math.random(150,350)
gBox:setFillColor(0,255,0)

local planet = display.newRect(0,0,50,50)

local function onTouch(event)
local t = event.target
local phase = event.phase

if “began” == event.phase then
display.getCurrentStage():setFocus( t )
t.isFocus = true
gBox:setFillColor(255,0,0)
– Store initial position
t.x0 = event.x - t.x
t.y0 = event.y - t.y

elseif t.isFocus then
if “moved” == phase then
t.x = event.x - t.x0
t.y = event.y - t.y0

elseif “ended” == phase or “cancelled” == phase then
display.getCurrentStage():setFocus( nil )
t.isFocus = false

print(“YES!! Touching the gBox”)
end
end
– Stop further propagation of touch event!
return true
end
gBox:addEventListener(“touch”, onTouch)[/lua] [import]uid: 51459 topic_id: 17209 reply_id: 65083[/import]

Heres the code in a for loop and all the boxes change to red and working GREAT!!! THANKS FOR ALL THE HELP!!

[lua]display.setStatusBar( display.HiddenStatusBar ) – HIDE STATUS BAR

local gameState = 0

local _W = display.contentWidth
local _H = display.contentHeight

local rectTable = {}

local function onTouch(event)

local t = event.target
local phase = event.phase
local id = event.target.id

if “began” == event.phase then
display.getCurrentStage():setFocus( t )
t.isFocus = true
print(id)
rectTable[id]:setFillColor(255,0,0)

– Store initial position
t.x0 = event.x - t.x
t.y0 = event.y - t.y

elseif t.isFocus then
if “moved” == phase then
t.x = event.x - t.x0
t.y = event.y - t.y0

elseif “ended” == phase or “cancelled” == phase then
display.getCurrentStage():setFocus( nil )
t.isFocus = false

print(“YES!! Touching the gBox”)
end
end
– Stop further propagation of touch event!
return true
end

for i=1,5 do

local imgRect = display.newRect(0,0,50,50)
imgRect.x = math.random(150,200) ; imgRect.y = math.random(150,350)
rectTable[i] = imgRect
rectTable[i].id = i
rectTable[i]:setFillColor(0,255,0)
rectTable[i].x = math.random(50,350)
rectTable[i].y = math.random(50,350)
rectTable[i]:addEventListener(“touch”, onTouch)
print(rectTable[i].id)
end[/lua] [import]uid: 51459 topic_id: 17209 reply_id: 65086[/import]