Woking A Button In Mini Golf

I am trying to incorporate a button that takes the difference between start time when you first click it and the end time and then relates the difference to a power factor. In a real mini-golf game, the power factor will change the impulse, but for now I’m trying to change the gravity. All the program does so far is spawn a ball on click, and then the ball falls.

The problem I’m having is that after you spawn the ball, my clicks on the button are ignored. Help? Thanks to everyone who takes time to read this.

local physics = require “physics”

physics.start() 

physics.setGravity(0,9.8)

local physicsData = (require “shapedefs”).physicsData(1.0)

local whiteballdata = (require “whiteball”).physicsData(1.0)

local ball 

display.setStatusBar( display.HiddenStatusBar)

local function spawnBall(x,y)

  if ball and ball.x  then

    print (“already on screen”)

  else 

    ball = display.newImage(“ball.png”)

    ball.x = x

    ball.y = y

    ball:scale(.04,.04)

  end

end

    

local function myTouchListener( event )

print (“Touch X = #”…event.x)

print (“Touch Y = #”…event.y)

if event.phase == “ended” or event.phase == “cancelled” then

    spawnBall( event.x, event.y)

    end

end

Runtime:addEventListener( “touch”, myTouchListener )

local background = display.newImage(“golf.jpg”)

background.x=(257)

background.y=(185)

local golfwalls = display.newImage(“golfwalls.png”)

golfwalls.x=(260)

golfwalls.y=(165)

physics.addBody(golfwalls, “static”, physicsData:get(“golfwalls”))

local myButton = 

        display.newImage(“power-button-red-md2.png”)

myButton:scale(0.5, 0.5)

local secondsPassed

myButton.gettingTime = false

function myButton:tap (event)

   if ( myButton.gettingTime == false ) then

      myButton.gettingTime = true

      myButton.markTime = system.getTimer()

   elseif ( myButton.gettingTime == true ) then

      myButton.gettingTime = false

      secondsPassed = system.getTimer() - myButton.markTime

   end

end

myButton:addEventListener(“tap”, myButton)

local secondsPassed myButton.gettingTime = false   

function myButton:tap (event)    

if ( myButton.gettingTime == false ) then       

myButton.gettingTime = true       

myButton.markTime = system.getTimer()    

elseif ( myButton.gettingTime == true ) then       

myButton.gettingTime = false       

secondsPassed = system.getTimer() - myButton.markTime

setGravity(0, secondsPassed*9.8)

physics.addBody(ball, whiteballdata:get(“ball”))

    

end 

end