0

any way to cancel or stop touch function when touch function is running ? I have a hang on using drag and drop function, when click the object and hold it until the timer is 0 appeared popup dialog and i have a hang all of button such as back button dosen't work,

Problem Solve : you must remove the object to stop the function use object:removeSelf()

Thanks everyboy for your help :)

  • 1
    Welcome to Stackoverflow! Can you show your code so that we can help you. – JLONG Jun 27 '15 at 07:02
  • i'm sorry but my code is too long, my problem when click objet with event touch/drag and drop function, when event click/began or drag object/move and then hold it/not take off the finger/endeen until timer down 0, when timer is 0 and popup dialog show any button event listener doesn't work, pop up dialog using set alpha 1-0 to performed when timer down 0 @JLONG – user3718787 Jun 27 '15 at 07:53
  • Just show the relevant code. i.e. the touch listener and your timer. I may be able to help you out if you show the code. – JLONG Jun 27 '15 at 08:07
  • This will probably be of some assistance: [MCVE](http://stackoverflow.com/help/mcve) – kylieCatt Jun 27 '15 at 17:06

1 Answers1

0

Sorry for the delay. I noticed that you are not clearing the Focus on the object you are dragging. You must first clear the focus of your previous touch listener in order for the code to recognize a new touch even if you removed the event listener the focus is still there:

local objectTouched --This is to get the event.target.id that you will use later assuming that your event.target.id is a number

local function dragAndDrop (e)

    target = {}
    distanceBetweeen = {}

    objectTouched = event.target.id

    for i = 1, #checkPoint do 
        target[i] = checkPoint[i]
    end


        if e.phase == "began" then

            --YOUR CODE

        elseif e.phase == "moved" then

            --YOUR CODE

        elseif e.phase == "ended" then

            --YOUR CODE

        elseif e.condition == "forceCancelled" then

             -- ADD THIS CONDITION SO THAT THE FUNCTION WILL REMOVE -- THE FOCUSED OBJECT FIRST

            display.getCurrentStage():setFocus(nil)

        end

end


function timeoutGame()
    --BEFORE YOU REMOVE THE EVENT LISTENER CALL THIS FIRST
    ilusi[objectTouched]:dispatchEvent({name = "touch", target = ilusi[objectouched], condition = "forceCancelled"})
    timeoutGroup.alpha = 1 
    timeoutGroup:toFront()
    btnPause:removeEventListener("tap", pauseGame)
    btnReload:removeEventListener("tap", goTo)

    for i=1, #jawabanPasti do
        ilusi[i]:removeEventListener ("touch",dragAndDrop)
    end   


end
JLONG
  • 805
  • 10
  • 20