在 Flex 4.5 中,如何使用 ActionScript(不是 MXML)将工具提示添加到 TextFlow (TLF) 内的 InlineGraphicElement?
var newParagraph : ParagraphElement = new ParagraphElement();
var icon : InlineGraphicElement = MY_ICON;
// icon.toolTip = "boo" ????
newParagraph.addChild( icon );
我想要一个“图标”的特定工具提示。我读过有关使用 HTML 以及 rollOver 和 rollOut 的内容(例如 谢谢,先生),但我'我将其构建为更大文本块的一部分;中间很难从增量对象切换到 HTML。
如果我无法在图标上设置事件,我可以在 ActionScript 中创建一个 HTML 位作为段落的一部分(但不是全部)吗?
干杯
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我刚刚遇到了同样的问题。
我发现的最简单的解决方案是将 InlineGraphicElement 包装在 LinkElement 中。
LinkElement 已调度鼠标事件。
I just came across the same problem.
The easiest solution i found was wrapping my InlineGraphicElement in a LinkElement.
The LinkElement already dispatches mouse events.
问题(我确信您已经发现)是文本流元素不是显示对象,因此不实现正常的显示对象行为。
您需要做的是创建一个自定义 InlineGraphicElement 来附加您需要的事件侦听器,然后从 textFlow 实例分派一个事件,以便可以在显示对象层次结构中的某个位置读取该事件(或者您选择的任何目标方法)事件)。
您可以通过查看 LinkElement (请参阅 createContentElement 函数)。
不幸的是 InlineGraphicElement 被标记为最终的,因此您需要复制它的功能而不是扩展它。只需确保在代码中使用自定义图形元素代替普通图形元素即可。
祝你好运!
编辑
以防万一丢失了要点,我们的想法是,您可以通过将侦听器附加到 textFlow 来捕获应用程序中某处的鼠标事件,然后使用以下命令以编程方式创建工具提示并将其放置在元素上查找文本流元素边界的标准方法。
The problem (as I'm sure you found out) is that text flow elements are not display objects, and so do not implement the normal display object behavior.
What you need to do is create a custom InlineGraphicElement that attaches the event listeners you need, then dispatch an event off of the textFlow instance so it can be read in somewhere in your display object hierarchy (or whatever your method of choice is to target that event).
You can see a good example of how to add mouse interaction by looking at the source to the LinkElement (see the createContentElement function).
Unfortunately the InlineGraphicElement is marked final, so you will need to duplicate it's functionality rather then extend it. Just make sure to use the custom graphic element in your code in lieu of the normal one.
Best of luck!
edit
Just in case the point was lost, the idea is that you can capture the mouse event somewhere in your app by attaching a listener to the textFlow, then programmatically create and position a tool tip over the element using the standard methods to find the bounds of a text flow element.
当鼠标悬停在文本流组件上时,您可以进行一些命中测试。
假设您有一些像这样的文本流:
并且您侦听整个文本组件上的 mouseOver 事件。
然后要测试鼠标是否位于图像上,请实现 mouseOver 处理程序:
You can do some hit-testing when the mouse is over the textflow component.
Suppose you have some textflow like this:
And you listen for mouseOver events on the entire textcomponent.
Then to test if the mouse is over your image, implement the mouseOver handler: