在某些情况下无法单击 Spark List ItemRenderer 上的按钮

发布于 2025-01-07 17:35:09 字数 1589 浏览 1 评论 0原文

我有一个带有我自己的自定义渲染器的 Spark 列表。当用户将鼠标悬停在列表中的项目上时,行中会出现左右按钮,允许用户更改正在呈现的值的值。例如,如果有 5 个优先级(1 到 5),则左侧按钮会减小值,右侧按钮会增加值。

快速说明:它们并不是真正的按钮,而是 s:Images 设计为像按钮一样工作。

现在,这工作正常,除了在一种特定条件下:如果用户选择该行,然后将光标移出行,然后返回行,当用户单击任一按钮时,什么也没有发生。尽管这种情况听起来很复杂,但这是测试用户一直在做的事情!这对他们来说实在是令人沮丧。

我发现了这种行为的原因:按钮仅在项目渲染器的悬停和选定状态下显示。这就是我想要发生的事情 - 除非用户的指针能够按下按钮,否则按钮不应该可见。当在列表中选择某个项目时,渲染器的状态将变为“已选择”。再次单击不会更改状态。将指针移出该行,然后再次返回并单击(在已选定的行上)使该行的状态从选定状态变为正常状态(当鼠标按下时),然后返回到选定状态(当鼠标松开时)。我觉得这很奇怪!这意味着按钮实际上在正常状态下消失(它应该),因此没有被单击)。

我曾考虑过,不知怎的,我可以让图像在项目渲染器的 Z 顺序中“更高”,因此它们在项目渲染器获取点击事件之前拦截它,但我无法让它工作。

有人可以帮忙吗?

如果有帮助的话,来自 ItemRenderer 的代码片段如下:

<s:HGroup width="150" verticalAlign="middle" verticalCenter="0">
  <s:Image id="previousItemButton" buttonMode="true" source="{_leftArrow}" width="16" height="16" visible.normal="false" visible.hovered="true" visible.selected="true" click="previousClicked(event)"/>
  <s:Label text="{data.outputFormat.value}" width="100%" click="nextClicked(event)"/>
  <s:Image id="nextItemButton" buttonMode="true" source="{_rightArrow}" width="16" height="16" visible.normal="false" visible.hovered="true" visible.selected="true" click="nextClicked(event)"/>
</s:HGroup>

更新:

该问题是由构成 ItemRenderer 的组件的最高级别上的虚假 rollOut 事件引起的。此 rollOut 调用了一个方法,其中包括:

protected function hgroup1_rollOutHandler(event:MouseEvent):void {
  if (this.selected) {
    this.selected = false;
  }
}

这是导致问题的原因,删除 rollOut 后该方法修复了问题。我不知道为什么在 mouseDown 上激活转出。

I have a Spark List with my own custom renderer. When the user rolls over an item in the list, left and right buttons appear in the row allowing the user to change the value of a value being rendered. For example, if there are 5 priorities (1 to 5), the left button decreases the value and the right button increases it.

Quick note: they're not really buttons, but s:Images designed to work like buttons.

Now this works fine, except under one particular condition: If the user selects the row, then moves the cursor out of the row, then back into the row, when the user clicks on either button, nothing happens. Even though this scenario sounds convoluted it's something the test users do all the time! It's really frustrating for them.

I have discovered the reason for this behaviour: The buttons are only displayed in the hover and selected states of the item renderer. This is what I want to happen - the buttons should not be visible unless the user's pointer is capable of pressing them. When an item is selected in the list the state of the renderer goes to selected. Clicking again doesn't change the state. Moving the pointer out of the row, then back in again and clicking (on the already selected row) makes the row's state go from selected, to normal (when mouse-down) and back to selected (on mouse-up). I find this very odd! It means that the button actually disappears when in state normal (which it should) thus isn't being clicked).

I had considered that somehow I could have the images "higher up" in the Z-order on the item renderer and thus they intercept the click event before the item renderer gets it, but I can't get this to work.

Can anyone help?

If it helps, a snippet from the ItemRenderer is below:

<s:HGroup width="150" verticalAlign="middle" verticalCenter="0">
  <s:Image id="previousItemButton" buttonMode="true" source="{_leftArrow}" width="16" height="16" visible.normal="false" visible.hovered="true" visible.selected="true" click="previousClicked(event)"/>
  <s:Label text="{data.outputFormat.value}" width="100%" click="nextClicked(event)"/>
  <s:Image id="nextItemButton" buttonMode="true" source="{_rightArrow}" width="16" height="16" visible.normal="false" visible.hovered="true" visible.selected="true" click="nextClicked(event)"/>
</s:HGroup>

UPDATE:

The issue was caused by a spurious rollOut event on the highest level of the components that made up the ItemRenderer. This rollOut called a method which consisted of:

protected function hgroup1_rollOutHandler(event:MouseEvent):void {
  if (this.selected) {
    this.selected = false;
  }
}

This was causing the problem and removing the rollOut and the method fixed the issue. Quite why a roll-out is being activated on mouseDown I don't know.

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文