长按spark.components.list项目

时间:2011-06-29 20:54:03

标签: flash flex actionscript-3 flash-builder flex4.5

有没有人知道在新版本的flex中是否有任何类型的长按手势(如在Android上)?

我希望长按时列表中的项目可编辑/删除,但我真的希望我不会用计时器和诸如此类的东西制作我自己的长按手势。

如果没有内置,有没有人知道有关如何制作长按手势的任何资源/博客文章 - 或者,还有如何制作可编辑列表?

3 个答案:

答案 0 :(得分:2)

flextras回答了这个问题,我只想跟进一个似乎有用的代码示例。现在,我只是做一个弹出窗口,询问您是否要从列表中删除该项目。

        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);
        }

我使用鼠标和触摸事件进行简单测试:

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

答案 1 :(得分:0)

基于ASdocs for the TouchEvent class

,看起来不像 实际上,我对此感到有些惊讶。您可以使用TOUCH_ENDTOUCH_BEGINtimer事件来模拟某些内容。

答案 2 :(得分:0)

查看Gestouch(开发分支是最新的) org.gestouch.gestures.LongPressGesture