开发者

Long-Press spark.components.list Item

Does anyone know if there is any sort of Long-Press gesture (like on Android) in the new version of flex?

I'm looking to make an item in a list editable/delete-able upon long-press, but I'm really hoping I wont have to make my own Long-Press gesture with a timer and whatnot.

If there is none built in, does anyone kno开发者_如何学Cw of any resources/blog posts about how to make a Long-Press gesture - or, furthermore, how to make an Editable list?


flextras answered it, and I just wanted to follow up with a code sample that seems to work. For now, I have it just do a popup asking if you want to delete the item from the list.

        private var deleteAlert:DeleteAlert = new DeleteAlert();
        private  var longPressTimer:Timer = new Timer(1500,1);

        protected function LoadChartView_viewActivateHandler(event:ViewNavigatorEvent):void {
            enableClick();
        }
        private function startLongPressMouse(event:MouseEvent):void {   
            startLongPressTimer();
            list.addEventListener(MouseEvent.MOUSE_MOVE, endLongPressMouse);
        }
        private function endLongPressMouse(event:MouseEvent):void {
            stopLongPressTimer();
            enableClick();
            list.removeEventListener(MouseEvent.MOUSE_MOVE, endLongPressMouse);
        }
        private function startLongPress(event:TouchEvent):void {
            startLongPressTimer();
            list.addEventListener(TouchEvent.TOUCH_MOVE, endLongPress);
        }
        private function endLongPress(event:TouchEvent):void {
            stopLongPressTimer();
            enableClick();
            list.removeEventListener(TouchEvent.TOUCH_MOVE, endLongPress);
        }
        private function startLongPressTimer():void {
            longPressTimer.start();
            longPressTimer.addEventListener(TimerEvent.TIMER_COMPLETE, longPressHandler);
        }
        protected function disableClick():void {
            trace("disable click");
            list.removeEventListener(MouseEvent.CLICK, regularClickHander);
        }
        public function enableClick():void {
            list.callLater(list.addEventListener, [MouseEvent.CLICK, regularClickHander]);
        }
        public function resetListSelection():void {
            list.selectedIndex = -1;
            list.validateDisplayList();
        }
        private function stopLongPressTimer():void{
            longPressTimer.stop();
            longPressTimer.reset()
        }
        public function longPressHandler(event:TimerEvent):void{
            disableClick();
            stopLongPressTimer();
            deleteAlert.addEventListener(PopUpEvent.CLOSE, popupClosedHandler);
            deleteAlert.open(this, false);
            PopUpManager.centerPopUp(deleteAlert);
        }
        public function popupClosedHandler(event:PopUpEvent):void{
            if (event.commit)data.removeItemAt(list.selectedIndex);
            callLater(resetListSelection);
        }

I used both the mouse and touch events for easy testing:

<s:List id="list" top="0" bottom="0" left="0" right="0"
        dataProvider="{data}"
        touchBegin="startLongPress(event)" touchEnd="endLongPress(event)"
        mouseDown="startLongPressMouse(event)" mouseUp="endLongPressMouse(event)">


Doesn't look like it, based on the ASdocs for the TouchEvent class:

I'm a bit surprised by that, actually. You can probably mock something up using the TOUCH_END and TOUCH_BEGIN events with a timer.


Take a look on Gestouch (develop branch is more up-to-date) org.gestouch.gestures.LongPressGesture

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜