禁用 itemrenderer 悬停状态
我的 itemrenderer 有 2 个自定义状态,没有悬停状态,也没有正常状态。
<s:states>
<s:State name="state1" />
<s:State name="state2" />
</s:states>
当我初始化它时,我强制它进入状态 2。问题是,当鼠标滚出
远离该项目时,它会重新回到第一个状态state1
。这有点奇怪,因为我实际上没有悬停/取消悬停状态。有谁知道如何防止这种情况发生?也许通过某种方式禁用 rollout
效果?
My itemrenderer has 2 custom states, no hovered state, and no normal state
<s:states>
<s:State name="state1" />
<s:State name="state2" />
</s:states>
When I initialize it, I force it to go to state2
. The problem is that when the mouse rolls out
away from the item, it relapses back to the first state state1
. It's kind of weird since I don't really have a hovered/unhover state. Anyone knows how to prevent this from happening? maybe by somehow disabling the rollout
effect?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
更新
为我解决了这个问题:我正在从数据提供者设置和读取当前状态。
“正常”和“悬停”始终基于当前状态,因此当您将鼠标悬停在 itemrenderer 上时不会发生任何变化。
“我不确定你所说的‘重置’是什么意思。”
我这里也有同样的问题。
他希望在推出时保持状态。这与样式无关。这只是关于各州的事情。
我已经找到了这个,但我无法在我的构建中使用它。
http://ianserlin.com/index.php/2009/12/15/disabling-rollout-behavior-of-a-selected-item-in-a-flex-4-list/
UPDATE
that solved it for me: i am setting and reading the current state from a dataprovider.
and "normal" and "hovered" are always based on the current state so nothing changes when you hover over itemrenderer.
"I'm not sure what you mean by "reset"."
i have the same problem here.
he wants to keep the state when a rollout occurs. this has nothing to do with the styles. its just about the states.
i have found this but i am not able to use it in my build up.
http://ianserlin.com/index.php/2009/12/15/disabling-rollout-behavior-of-a-selected-item-in-a-flex-4-list/
您可以通过深入研究 ItemRenderer 源代码来找到解决方案。搜索“rollout”会发现:
查看“itemRenderer_rollOutHandler”方法,它包含:
检查“hovered”成员,您可以看到它有一个 setter 函数:
其中一部分设置当前状态。好处是它是一个受保护的方法,这意味着我们可以重写它。因此,如果您从不在 ItemRenderer 中使用悬停状态,则将其添加到脚本块就足够了:
悬停状态和背景绘制不会因此发生,因此推出事件侦听器将不起作用,并且您的状态将不会发生。不会受到影响。
You can find the solution by digging into the ItemRenderer source. Searching for "rollout" finds this:
Looking at the "itemRenderer_rollOutHandler" method, it contains:
Checking out the "hovered" member, you can see that it has a setter function:
Part of this sets the current state. The good thing is that it's a protected method which means we can override it. So if you never use the hover state in your ItemRenderer, it is sufficient to add this to the script block:
The hovered state and background drawing will not happen as a result, so the rollout event listener will have no effect and your states won't be impacted.
最简单的解决方案是:
这样,当推出或取消选择时,您的项目渲染器将不会尝试切换到其“正常”状态。
我将它与验证器结合使用来设置渲染器的错误状态。工作起来就像一个魅力。
The simplest solution is:
This way when rolled out or deselected your item renderer won't try to switch to it's 'normal' state.
I used it in conjunction with Validators to set an error state of the renderer. Worked like a charm.
我会考虑对鼠标事件做一些事情,例如 MouseOver
http://docs.huihoo.com/flex/4/flash/display/InteractiveObject.html#event:mouseOver
但是,我很确定当您使用某些东西作为 itemRenderer 时,列表类可以对 itemRenderer 施加一些控制。 List 类完全有可能导致您看到的行为。你使用什么类?你的渲染器是什么?
I'd look into doing something with the mouse events, such as MouseOver
http://docs.huihoo.com/flex/4/flash/display/InteractiveObject.html#event:mouseOver
However, I'm pretty sure that when you use something as an itemRenderer, the list class can exert some control over the itemRenderer. It is entirely possible the List class is causing the behaviour you see. What class are you using? What is your renderer?
感谢您提供以下链接:
我也有类似的问题;根据数据,我有两种类型的正常状态,并且在鼠标移出后,我希望渲染器识别要恢复到两种状态中的哪一种。我使用了上面链接中给出的“覆盖函数”解决方案来达到预期的效果。
我的解决方案:
我刚刚在自定义 ItemRenderer 的块中输入了上述代码。
Thanks for the following link:
I had a similar issue; based on the data i had two types of normal states and after mouse-out, i wanted the renderer to identify which of the two states to revert to. I used the "override function" solution given in the above link to achieve the desired effect.
My Solution:
I just entered the above code in the block in my custom ItemRenderer.
ItemRenderers 实际上委托了它们的正常、悬停和渲染。选定的状态发送到名为 InteractiveStateDetector 的内部类,而不是发送到父列表。这可以通过简单地在简单 UI 中使用 ItemRenderer 并手动附加其数据来验证(make 和 itemRenderer 带有绑定到 currentState 值的标签是查看这一点的最简单方法)。您将看到它仍然根据当前的用户体验更改状态。
考虑到这一点,Adobe 巧妙地省略了任何禁用此功能而不会造成混乱的方法。但是,您可以按照 Dennis 的建议进行操作,并在大多数用例中覆盖 getCurrentRendererState 函数。
我的特定用例是,我想在非渲染器设置中利用我的 itemRenderer,仅进行较小的状态更改,但它没有识别出我将其 currentState 声明为“nonRenderer”。它将默认为“正常”。
ItemRenderers actually delegate their normal, hover & selected states to an internal class called InteractiveStateDetector, not to a parent list. This can be verified by simply using an ItemRenderer in a simple UI and manually attaching its data (make and itemRenderer with a label bound to the currentState value is the easiest way to see this). You will see that it still changes state based on the current UX.
With that in mind, Adobe has brilliantly left out any means of disabling this without getting messy. However you can do as Dennis suggests and override the getCurrentRendererState function for most use cases.
My particular use case was that I wanted to leverage my itemRenderer in a non-renderer setup with only minor state changes, but it didn't recognize that I declared its currentState to "nonRenderer". It would default to "normal".