how to change scene when two objects collide

i have been working on my first game and i almost done with it.all my function are working correctly

but i am stuck at one function of collision when two objects(dynamic) collide with each other due to gravity.

what i did is-- i wrote above the create scene function

function firstcollision(event)

 if(event.phase==“began”) then

storyboard.gotoScene(“gameover”)

print(“collide”)

end

end

and added the event listener in enter scene

Runtime:addEventListener(“collision”,firstcollision)

collide word was printed but the scene did not changed.i am not able to understand where did i go wrong.

try out this

object1.name =“object1”

object2.name =“object2”

local function onCollision(event)

  if event.phase==“began” then

    if event.object1.name ==“object1” and event.object2.name==“object2” then 

          storyboard.gotoScene(“gameover”)

    end 

  end 

end 

Runtime:addEventListener(“collision”,onCollision) 

yes,i tried it but its still not working.

try adding an event listener to which ever  object is being hit.

ex. 

 if a rock is thrown and is going to hit the ground, add an event listener to the ground.

if both objects are moving, then add an event listener to one of them

try

 object1:addEventListener( “collision”, name of function)

thanks you,now its working.i also want to know one more thing about scenes

when we create an object say a box(a global variable) in create scene and we want to remove it in exit scene or destroy scene i.eonce the scene has ended then how can i do that?

in scene hide, put 

nameofObject:removeSelf

nameofObject = nil

try out this

object1.name =“object1”

object2.name =“object2”

local function onCollision(event)

  if event.phase==“began” then

    if event.object1.name ==“object1” and event.object2.name==“object2” then 

          storyboard.gotoScene(“gameover”)

    end 

  end 

end 

Runtime:addEventListener(“collision”,onCollision) 

yes,i tried it but its still not working.

try adding an event listener to which ever  object is being hit.

ex. 

 if a rock is thrown and is going to hit the ground, add an event listener to the ground.

if both objects are moving, then add an event listener to one of them

try

 object1:addEventListener( “collision”, name of function)

thanks you,now its working.i also want to know one more thing about scenes

when we create an object say a box(a global variable) in create scene and we want to remove it in exit scene or destroy scene i.eonce the scene has ended then how can i do that?

in scene hide, put 

nameofObject:removeSelf

nameofObject = nil