B4J Question [SOLVED] Variable change ignored by a label's event. I'm confused...

MegatenFreak

Active Member
Licensed User
Hello. Consider this code please:
B4X:
Private Sub MyLabel_MouseClicked (EventData As MouseEvent)
    Working = True
    Do While Working
        Log("Button's still down")
        Sleep(500)
    Loop
End Sub

Private Sub MyLabel_MouseReleased (EventData As MouseEvent)
    Working = False
    Log("Button has been released")
End Sub
What I expect, naturally, is that as long as the mouse is kept held on the label, I'd get the "button still down" message every half second, but once the mouse button is released, it should stop. But, surprisingly, the loop continues. In other words, although the boolean variable "Working" is set to "false", the first event still treats it as "true", ignoring the change in its value.

* Log output: *
Button has been released
Button's still down
Button's still down
Button's still down
Button's still down
......

What's crazy is that the mechanism works fine when I test it in an empty project.
Any ideas what's happening here?
Thanks.
 

MegatenFreak

Active Member
Licensed User
[SOLVED] :
I should've used the MousePressed event instead of the MouseClicked event, as the latter is only triggered once the button is released, and the released event takes precedence.
What is blowing my mind is that the empty project i tested it uses MousePressed! I have no idea what happened here.. perhaps a paranormal entity interfered...
 
Upvote 0
Top