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

例如,假设我点击对象A,然后长按对象B:longPressHandler将在编辑窗口中“打开”对象A。我已经调试,并且看到列表的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更改为仅显示所选项目的名称,而不是打开编辑窗口。

让我知道您是否需要更多信息。预先感谢您的帮助!

最佳答案

一种方法是创建一个自定义事件(具有自定义属性),以便您可以在调度事件时传递所需的任何数据。

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:我想在评论中添加此内容,但作为输入的内容会变得更大:)

关于actionscript-3 - Flash Builder长按列表-移动,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/14740768/

10-13 00:33