List 组件上的 itemRollOver 和 itemRollOut 事件存在问题

发布于 2024-07-09 11:21:32 字数 213 浏览 6 评论 0原文

我已经在列表组件上设置了 itemRollOveritemRollOut 事件侦听器,但是每当我将鼠标滚动到列表项上时,同一列表项的 over 和 out 事件都会发生接连不断地开火。 我的列表使用自定义 itemRenderer。

有什么想法可能是为什么吗? Adobe 文档没有提供对此的深入了解(毫不奇怪......)。

I have set the itemRollOver and itemRollOut event listeners on a List component, but whenever I roll the mouse over a list item, both the over and out events of the same list item fire in succession right after each other. My list uses a custom itemRenderer.

Any ideas why this might be? The Adobe documentation doesn't provide much insight into this (not surprisingly...).

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

jJeQQOZ5 2024-07-16 11:21:32

在我看来这是一个错误。 ListBase.mouseOverHandler 现在在调度 ITEM_ROLL_OVER 事件时设置一个名为 lastHighlightItemRendererAtIndices 的变量,然后在调度 ListBase.clearHighlight 中的 ITEM_ROLL_OUT 事件(由 mouseOutHandler 调用)时使用该变量(与 lastHighlightItemIndices 一起)。

问题是,当您从行到行移动鼠标时,首先调用 mouseOverHandler,设置 lastHightlight... 变量,然后当随后调用 mouseOutHandler 时,它使用刚刚设置的 lastHighlight... 值结果是您为同一渲染器获得连续的“roll over”和“roll out”事件。

坦率地说,我不知道为什么 ListBase.clearHighlight 在分派 ITEM_ROLL_OUT 事件时不使用传入的渲染器(这就是它在 SDK 2 中的工作方式),因为这是正在“推出”的实际渲染器。

In my opinion this is a bug. The ListBase.mouseOverHandler now sets a variable called lastHighlightItemRendererAtIndices when it dispatches an ITEM_ROLL_OVER event, which is then used (together with lastHighlightItemIndices) when dispatching an ITEM_ROLL_OUT event in ListBase.clearHighlight (called by the mouseOutHandler).

The problem is that when you mouse from row-to-row the mouseOverHandler is called first, setting the lastHightlight... variables, and then when the mouseOutHandler gets called subsequently, it uses the lastHighlight... values that were just set with the result that you get consecutive 'roll over' and 'roll out' events for the same renderer.

Frankly I don't know why ListBase.clearHighlight just doesn't use the passed in renderer when dispatching the ITEM_ROLL_OUT event (which is how it used to work in SDK 2) as this is the actual renderer that is being 'rolled out of'.

锦爱 2024-07-16 11:21:32

它们来自同一个物体吗?
如果不是,您很可能会从您刚刚离开的“项目”中获得一个 itemRollOut ,并从您输入的新项目中获得一个 itemRollOver ,具体取决于它们的间距,并且这些项目可能会彼此非常接近地触发。

Are they coming from the same object?
If not you will it is likely so that you will get an itemRollOut from the "item" you just left and a itemRollOver from the new one you entered, depending on their spacing and such these may fire very close to each other.

江城子 2024-07-16 11:21:32

如果您要覆盖 set data(),请确保在项目渲染器中设置 super.data

ListBase 侦听 MOUSE_OVER,然后根据鼠标坐标和项目渲染器的位置计算出其下方的项目。 您可以检查 ListEvent.itemRenderer 以查看哪个渲染器的翻转和推出正在触发以及按什么顺序触发。

最坏的情况是,您可以在项目渲染器中监听 rollOver 和 rollOut。

Make sure you are setting super.data in your item renderer if you are overriding set data().

ListBase listens for MOUSE_OVER and then figures out the item underneath it based on coordinates of mouse and the position of the item renderer. You could check ListEvent.itemRenderer to see which renderer's roll over and roll out are firing and in what order.

Worst case, you could listen for rollOver and rollOut inside your item renderer.

°如果伤别离去 2024-07-16 11:21:32

有同样的问题。 super.data 已经被设置,并且 rollOut 和 rollOver 事件的项目是相同的。 我最终选择了 anirudhsasikumar 最坏的情况,并在项目渲染器内监听 rollOver 和 rollOut。 似乎工作正常。

Had the same problem. super.data was already being set, and the item is the same for the rollOut and rollOver event. I ended up opting for anirudhsasikumar's worst case scenario, and listened for rollOver and rollOut inside the item renderer. Seems to work fine.

多情出卖 2024-07-16 11:21:32

我也遇到了同样的问题。 我最终对 mx.controls.List 类进行子类化并重写clearHighlight 函数。 据我所知,lastHighlightItemIndices 变量仅在该函数中读取。 因此,执行类似以下操作可以解决此问题:

import mx.core.mx_internal;

use namespace mx_internal;

public class List extends mx.controls.List
{
    public function List()
    {
        super();
    }

    override mx_internal function clearHighlight( item:IListItemRenderer ):void
    {
        var uid:String = itemToUID( item.data );

        drawItem( UIDToItemRenderer( uid ), isItemSelected( item.data ), false, uid == caretUID );

        var pt:Point = itemRendererToIndices( item );

        if( pt )
        {
            var listEvent:ListEvent = new ListEvent( ListEvent.ITEM_ROLL_OUT );

            listEvent.columnIndex = item.x;
            listEvent.rowIndex = item.y;
            listEvent.itemRenderer = item;

            dispatchEvent( listEvent );
        }
    }
}

然后只需使用此 List 类而不是 Adob​​e 类,您就会获得预期的行为。 我针对 Flex SDK 3.2 对此进行了测试,它有效。

<mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml" xmlns:controls="com.example.controls.*">

    [ other code ... ]

    <controls:List itemRollOver="onItemRollOver( event )" itemRollOut="onItemRollOut( event )" />

</mx:Canvas>

感谢吉诺·巴索在上面的帖子中提出的想法。 希望有帮助。

I was having this same issue. I ended up subclassing the mx.controls.List class and overriding the clearHighlight function. As far as I can tell, the lastHighlightItemIndices variable is only ever read in that function. So doing something like the following fixed this issue:

import mx.core.mx_internal;

use namespace mx_internal;

public class List extends mx.controls.List
{
    public function List()
    {
        super();
    }

    override mx_internal function clearHighlight( item:IListItemRenderer ):void
    {
        var uid:String = itemToUID( item.data );

        drawItem( UIDToItemRenderer( uid ), isItemSelected( item.data ), false, uid == caretUID );

        var pt:Point = itemRendererToIndices( item );

        if( pt )
        {
            var listEvent:ListEvent = new ListEvent( ListEvent.ITEM_ROLL_OUT );

            listEvent.columnIndex = item.x;
            listEvent.rowIndex = item.y;
            listEvent.itemRenderer = item;

            dispatchEvent( listEvent );
        }
    }
}

Then just use this List class instead of the Adobe one and you'll have the behavior you expect. I tested this against Flex SDK 3.2 and it works.

<mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml" xmlns:controls="com.example.controls.*">

    [ other code ... ]

    <controls:List itemRollOver="onItemRollOver( event )" itemRollOut="onItemRollOut( event )" />

</mx:Canvas>

Thanks to Gino Basso for the idea in the post above. Hope that helps.

深居我梦 2024-07-16 11:21:32

感谢您的解决方案。 这确实解决了问题! 不过,有一个小修正:

listEvent.columnIndex = item.x;
listEvent.rowIndex = item.y;

应该是

listEvent.columnIndex = pt.x;
listEvent.rowIndex = pt.y;

item.x 和 y 保存渲染器的坐标(以像素为单位)。

Thanks for the solution. That really solved the problem! Small correction, though:

listEvent.columnIndex = item.x;
listEvent.rowIndex = item.y;

should be

listEvent.columnIndex = pt.x;
listEvent.rowIndex = pt.y;

item.x and y hold the coordinate of the renderer in pixels.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文