长期preSS spark.components.list项目项目、spark、preSS、list

2023-09-08 13:55:52 作者:少年多梦,不多心

有谁知道是否有(像在Android)的柔性新版任何形式的庆龙preSS的姿态?

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

我期待在做一个列表编辑项/删除,能够在长期preSS,但我真的希望我不会有让我自己庆龙preSS的姿态与计时器和诸如此类的东西。

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.

如果有没有内置的,没有人知道如何使远攻preSS姿态的任何资源/博客文章 - 或者,此外,如何使一个可编辑列表

If there is none built in, does anyone know of any resources/blog posts about how to make a Long-Press gesture - or, furthermore, how to make an Editable list?

推荐答案

flextras回答了这个问题,我只是想跟进一个code样品,似乎工作。现在,我有它只是一个弹出窗口,询问您是否想从列表中删除的项目。

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)">