fljot / Gestouch

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

Dispatch SwipeGesture to repeat Event #99

Closed wztechno closed 8 years ago

wztechno commented 8 years ago

Hello and thank you for great Library,

I would like to ask for help if you please,

I have a ScrollContainer that contains many LayoutGroups. The ScrollContainer is scrollable. As the scrollContainer does not allow for swipe events to be passed to its children while scrolling, I would like to listen for Swipe Event on Scroll Container to stop the scrolling and then repeat the exact swipe event which will then fire it to the Children. I am not able to dispatch the swipe event. It alaways says undefined error. Any help is appreciated. Here is the code.

    var swipe:SwipeGesture = new SwipeGesture(scrollContainer);
            swipe.direction = SwipeGestureDirection.LEFT;
            swipe.addEventListener(GestureEvent.GESTURE_RECOGNIZED, repeatSwipeEvent);
            function repeatSwipeEvent(event:GestureEvent):void{
                scrollContainer.stopScrolling();
                var swap:SwipeGesture = new  SwipeGesture(event.target.target);
                swap.dispatchEvent(event);
            }
fljot commented 8 years ago

@wztechno I lost you at "As the scrollContainer does not allow for swipe events...". And the code doesn't seem to make any sense. So maybe you try to explain what you're trying to solve/achieve without going into technical implementation details?

wztechno commented 8 years ago

I am really sorry for my bad english as I don't speak english natively, and thank you for reply

idea:

1) Listen to SwipeGesture on ScrollContainer (I was able to do) 2) When SwipeGesture is triggered, stop the ScrollContainer Scrolling (I was able to do) 3) I need Repeat the exact SwipeGesture Event (as if the user finger has swiped the screen again) (not finding a way to do it) 4) This will trigger a new Swipe Event to be passed to ScrollContainer Children. (I was able to do)

Any idea how point 3 can be done ?

Hope I was able to explain myself well this time :)

fljot commented 8 years ago

@wztechno no, I asked you to explain without going deep into technical aspect. Are you trying to swipe on some element in the scrolling list so it would go side, like on some mobile interfaces?

wztechno commented 8 years ago

yes exactly ..

fljot commented 8 years ago

@wztechno well first of all let me suggest it's not the best idea from the UX perspective to stop the scrolling in this case. Anyway, what you want is to notify some element that swipe happened and probably pass some more info. So your first task is to find the element under touch (where swipe happened). To do it you could, for example, use gesture.location – which is Point in global (stage) coordinate space. Once you have reference to the element notify it by calling custom method, e.g.:

private function onSwipeRecognized(event:GestureEvent):void {
    var point:Point = swipeGesture.location;// do some appropriate globalToLocal() business
    var myListItem:MyListItem = getListElementUnderPoint(point);
    myListItem.doSomething();// or myListItem.onSwiped()
    // this can be myListItem.dispatchEvent(...MyEvent.SWIPED) if that's what you need
}

I'm not sure what you meant by "I need Repeat the exact SwipeGesture Event". Event has already happened. If you got it – it means you were notified. You need to handle it.

wztechno commented 8 years ago

That solved my problem .. thank u so much for great library

fljot commented 8 years ago

@wztechno cheers!