Group objects with touch events inside a ScrollView widget

Hello!
I am trying to develop a simple scrollview menu with group objects inside it. But i have a serious problem…
When i touch objects for scrolling the scrollview menu ,for some reason is executed the touch event of group objects… :confused: How can i separate the different touches?
This is my code…

[code]


– scenetemplate.lua


local storyboard = require “storyboard”
local widget = require “widget”
local scene = storyboard.newScene()



– NOTE:

– Code outside of listener functions (below) will only be executed once,
– unless storyboard.removeScene() is called.



– BEGINNING OF YOUR IMPLEMENTATION

– Called when the scene’s view does not exist:
function scene:createScene( event )
local group = self.view
bg = display.newImageRect(“bg.png”,320,480)
bg.x = display.contentWidth/2
bg.y = display.contentHeight/2

logo = display.newImageRect(“logo.png”,260,96)
logo.x = display.contentWidth/2
logo.y = 100
group:insert(bg);
group:insert(logo);

Group1 = display.newGroup();
Group2 = display.newGroup();
Group3 = display.newGroup();

local scrollView = widget.newScrollView{
top = 250,
width = 320,
height = 200,
scrollWidth = 660,
scrollHeight = 200,
hideBackground=true,
maxVelocity=4,
maskFile=“mask.png”

}
scrollView.content.verticalScrollDisabled = true
scrollView.content.horizontalScrollDisabled= false
scrollView.isHitTestMasked = true;

local pic1 = display.newImageRect(“m1.png”, 84, 123)
Group1:insert(pic1);

Group1:setReferencePoint(display.CenterReferencePoint)
Group1.x=pic1.width/2 +10
Group1.y=scrollView.height/2

function Group1:touch(event)
if event.phase == “began” then
print( “begin phase” )
Group1:remove(pic1);
pic1 = display.newImageRect(“m1_.png”,84,123);
Group1:insert(pic1);
display.getCurrentStage():setFocus( self )
self.isFocus = true

elseif self.isFocus then
if event.phase == “moved” then
print( “moved phase” )

elseif event.phase == “ended” or event.phase == “cancelled” then
print( “ended phase” )
display.getCurrentStage():setFocus( nil )
self.isFocus = false
storyboard.gotoScene(“scene1”);
end
end

return true
end
Group1:addEventListener( “touch”, Group1 )
scrollView:insert(Group1)

local pic2 = display.newImageRect(“m2.png”, 84, 123)
Group2:insert(pic2);

Group2:setReferencePoint(display.CenterReferencePoint)
Group2.x=Group1.x+pic1.width +10
Group2.y=scrollView.height/2

function Group2:touch(event)
if event.phase == “began” then
print( “begin phase” )
Group2:remove(pic2);
pic2 = display.newImageRect(“m2_.png”,84,123);
Group2:insert(pic2);
display.getCurrentStage():setFocus( self )
self.isFocus = true

elseif self.isFocus then
if event.phase == “moved” then
print( “moved phase” )

elseif event.phase == “ended” or event.phase == “cancelled” then
print( “ended phase” )
display.getCurrentStage():setFocus( nil )
self.isFocus = false
storyboard.gotoScene(“scene1”);
end
end

return true
end
Group2:addEventListener( “touch”, Group2 )
scrollView:insert(Group2)

local pic3 = display.newImageRect(“m3.png”, 84, 123)
Group3:insert(pic3);

Group3:setReferencePoint(display.CenterReferencePoint)
Group3.x=Group2.x+pic1.width +10
Group3.y=scrollView.height/2

function Group3:touch(event)
if event.phase == “began” then
print( “begin phase” )
Group3:remove(pic3);
pic3 = display.newImageRect(“m3_.png”,84,123);
Group3:insert(pic3);
display.getCurrentStage():setFocus( self )
self.isFocus = true

elseif self.isFocus then
if event.phase == “moved” then
print( “moved phase” )

elseif event.phase == “ended” or event.phase == “cancelled” then
print( “ended phase” )
display.getCurrentStage():setFocus( nil )
self.isFocus = false
storyboard.gotoScene(“scene1”);
end
end

return true
end
Group3:addEventListener( “touch”, Group3 )
scrollView:insert(Group3)

group:insert(scrollView);


– CREATE display objects and add them to ‘group’ here.
– Example use-case: Restore ‘group’ from previously saved state.


end
– Called immediately after scene has moved onscreen:
function scene:enterScene( event )
local group = self.view


– INSERT code here (e.g. start timers, load audio, start listeners, etc.)


end
– Called when scene is about to move offscreen:
function scene:exitScene( event )
local group = self.view
storyboard.removeScene( “scenetemplate” )

– INSERT code here (e.g. stop timers, remove listeners, unload sounds, etc.)


end
– Called prior to the removal of scene’s “view” (display group)
function scene:destroyScene( event )
local group = self.view


– INSERT code here (e.g. remove listeners, widgets, save state, etc.)


end

– END OF YOUR IMPLEMENTATION

– “createScene” event is dispatched if scene’s view does not exist
scene:addEventListener( “createScene”, scene )

– “enterScene” event is dispatched whenever scene transition has finished
scene:addEventListener( “enterScene”, scene )

– “exitScene” event is dispatched before next scene’s transition begins
scene:addEventListener( “exitScene”, scene )

– “destroyScene” event is dispatched before view is unloaded, which can be
– automatically unloaded in low memory situations, or explicitly via a call to
– storyboard.purgeScene() or storyboard.removeScene().
scene:addEventListener( “destroyScene”, scene )


return scene [import]uid: 185094 topic_id: 33171 reply_id: 333171[/import]