fljot / Gestouch

Gestouch: multitouch gesture recognition library for Flash (ActionScript) development.
MIT License
355 stars 85 forks source link

TapGesture with event.target.name #46

Closed Mona109 closed 11 years ago

Mona109 commented 11 years ago

Hello, I have a Sprite with several buttons in it, the buttons have names that are used to create new objects. Before Gestouch I used MouseClick, so event.target.name worked fine. Now with tap it doesn't. How can event.target.name be used with the TapGesture?

fljot commented 11 years ago

Event is dispatched by the gesture, so event.target is Gesture and event.target.target is your Sprite, so name is event.target.target.name (casting is omitted).

Mona109 commented 11 years ago

Thanks for the quick reply. I tried, but didn't work. Here what I tried: tapStart = new TapGesture(theSprite.hisChild); tapStart.addEventListener(org.gestouch.events.GestureEvent.GESTURE_RECOGNIZED, startIt);
function startIt(event:org.gestouch.events.GestureEvent):void{ const tap:TapGesture = event.target as TapGesture; if (tap.target.name == "Start_01") { testField.text = "inside"; } }

fljot commented 11 years ago

What didn't work? You realize that tap.target === theSprite.hisChild, right?

Mona109 commented 11 years ago

Yes I think so, it doesn't take the right name. Now I made some testing, so the Tap is working, but it doesn't take the right name. when I trace the name, it is for every button "instance12". With the MouseClick it worked fine, do you have an idea whats wrong?

fljot commented 11 years ago

With MouseClick you probably were using event bubbling (if you talk about event.target instead of event.currentTarget).

Mona109 commented 11 years ago

I don't really understand. Well now I found out that "instance12" is the Sprite where the buttons are inside. But I need to trigger the buttons. How may I get the buttons and their names with the TapGesture?

fljot commented 11 years ago

Option 1: attach TapGesture to every button. This way event.target.target is your button. Option 2: attach TapGesture to buttons container, then use some sort of hit-test to get the button under tap.location (point in global coordinate space)

Mona109 commented 11 years ago

Now it's fine, I tried both with success and I think Option1 would be better in my project. Thank you so much!

fljot commented 11 years ago

Just curious, why are you switching from MouseEvent.CLICK to Gestouch & TapGesture?