Closed Mona109 closed 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).
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";
}
}
What didn't work? You realize that tap.target === theSprite.hisChild
, right?
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?
With MouseClick you probably were using event bubbling (if you talk about event.target
instead of event.currentTarget
).
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?
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)
Now it's fine, I tried both with success and I think Option1 would be better in my project. Thank you so much!
Just curious, why are you switching from MouseEvent.CLICK to Gestouch & TapGesture?
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?