Are two different methods in hotspot possible?


#1

I would like to provide two different methods in one identical area:

append(UIButton, :function1).on(:touch) do |sender|
function1
and

append(UIButton, :function2).on(:touch_down_repeat) do |sender|
function2

Placing the methods function1 and function2 in the stylesheet in the same area, only function2 will be working while function1 is in the layer below, covered.

Is there any solution to the problem?

I image something like this:

append(UIButton, :function1).on(:touch) do |sender|
function1
and
append(UIButton, :function2).on(:touch_down_repeat) do |sender|
function2
end

Thanks for helping!
Daniel


#2

Not exactly sure what you want, but I’m pretty sure you don’t want to put this in a stylesheet (assuming RedPotion). Put that in the screen class.


#3

@hboon,
sorry, I had not been clear:
Of course the two methods (function1 and function2) are being placed in the screen class.
They work fine as long as they are not placed at the same area. But this is what I need.

In my app the user is supposed to evaluate a certain area on the display:
Tapping it once it should create effect #1, while tapping it twice it should create effect #2.


#4

Then you want something like this:

button = append(UIButton, :function1)
button.on(:touch) do |sender|
  function1
and
button.on(:touch_down_repeat) do |sender|
  function2
end

What you did originally was to add 2 buttons.

You probably shouldn’t name it as :function1 as it’s going to be confusing down the road, ie.:

button = append(UIButton, :my_button)

#5

Dear @hboon,

Thanks a lot for the code!
I could not make it work until I found out that in the middle I have to substitute the ‘and’ by ‘end’.
Now it works fine.

Thanks again,
Daniel


#6