Flash Builder长按List - Mobile

时间:2013-02-06 23:19:31

标签: actionscript-3 flex list mobile flash-builder

我想显示一个列表(在图块布局中,但我认为不会改变任何内容)并打开我长按的图块的编辑窗口(即按下至少1秒钟)。计时器启动正常,并在1秒后正确调用longPressHandler事件,但是,所选对象是我触摸的上一个对象。

例如,假设我点击了对象A,然后我长按对象B:longPressHandler将在编辑窗口中“打开”对象A.我已经调试了,我看到我的List的SelectedItem属性仅在我结束长按后更新(例如,在我拿起手指或释放鼠标按钮后)。有没有办法打开当前选择的项目?


相关动作脚本:

private  var longPressTimer:Timer = new Timer(1000,1);

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();
    lblD.text = "Long Press Detected on: " + list.selectedItem.className;
}

相关MXML:

 <s:List id="list"  dataProvider="{grades}" touchBegin="startLongPress(event)" touchEnd="endLongPress(event)"
        mouseDown="startLongPressMouse(event)" mouseUp="endLongPressMouse(event)"
        labelField="name"
        left.landscape="10" right.landscape="20" top.landscape="350" bottom.landscape="20"
        left.portrait="20" right.portrait="20" top.portrait="350" bottom.portrait="20">
    <s:itemRenderer>
        <fx:Component>
            <s:ItemRenderer width="100%" height="200">

                <s:Label text="{data.className}" top="30" horizontalCenter="0" color="#646464"/>
                <s:Label text="{data.credits}" top="50" horizontalCenter="0" color="#646464" fontSize="14"/>
                <s:Label text="{data.grade}" top="100" horizontalCenter="0" color="#646464" fontSize="14"/>
            </s:ItemRenderer>
        </fx:Component>
    </s:itemRenderer>
    <s:layout>
        <s:TileLayout requestedColumnCount="3" requestedColumnCount.landscape="4" columnAlign="justifyUsingWidth"/>
    </s:layout>
</s:List>

我将longPressHandler更改为只显示所选项目的名称,而不是打开编辑窗口。

如果您需要更多信息,请与我们联系。提前感谢您的帮助!

1 个答案:

答案 0 :(得分:0)

一种方法是创建自定义事件(使用自定义属性),以便在分派事件时传递所需的任何数据。

package events;
{
    import flash.events.Event;

    public class YourCustomEvent extends Event
    {
        public var yourData:Object;

        public function YourCustomEvent(type:String, yourData:Object)
        {
            super(type);
            this.yourData = yourData;
        }

        override public function clone():Event{
            return new YourCustomEvent(type, yourData);
        }
    }
}

希望它有所帮助!

PS:我想把它放在评论中,但它作为一个打字变得更大:)