在 Flex 4.5 中,如何使用 ActionScript(不是 MXML)将工具提示添加到 TextFlow (TLF) 内的 InlineGraphicElement?

发布于 2024-11-10 14:01:30 字数 450 浏览 5 评论 0 原文

var newParagraph : ParagraphElement = new ParagraphElement();

var icon : InlineGraphicElement = MY_ICON;
//   icon.toolTip = "boo"  ????
newParagraph.addChild( icon );

我想要一个“图标”的特定工具提示。我读过有关使用 HTML 以及 rollOver 和 rollOut 的内容(例如 谢谢,先生),但我'我将其构建为更大文本块的一部分;中间很难从增量对象切换到 HTML。

如果我无法在图标上设置事件,我可以在 ActionScript 中创建一个 HTML 位作为段落的一部分(但不是全部)吗?

干杯

var newParagraph : ParagraphElement = new ParagraphElement();

var icon : InlineGraphicElement = MY_ICON;
//   icon.toolTip = "boo"  ????
newParagraph.addChild( icon );

I want a specific toolTip for "icon". I have read about using HTML and rollOver and rollOut (e.g. Thanks, Mister), but I'm building this as part of a larger text block; it's difficult to switch from incremental objects to HTML in the middle.

If I cannot set an event on the icon, can I create an HTML bit in ActionScript as part (but not all) of a paragraph ?

Cheers

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

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

发布评论

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

评论(3

半山落雨半山空 2024-11-17 14:01:30

我刚刚遇到了同样的问题。

我发现的最简单的解决方案是将 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.

梦幻之岛 2024-11-17 14:01:30

问题(我确信您已经发现)是文本流元素不是显示对象,因此不实现正常的显示对象行为。

您需要做的是创建一个自定义 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.

十级心震 2024-11-17 14:01:30

当鼠标悬停在文本流组件上时,您可以进行一些命中测试。

假设您有一些像这样的文本流:

<s:RichEditableText width="100%" height="100%" mouseOver="toggleTooltip()">
    <s:textFlow>
        <s:TextFlow>
            <s:p>
                <s:span>Some text before</s:span>
                <s:img id="myImg" source="myImg.png" />
                <s:span>Some text after</s:span>
            </s:p>
        </s:TextFlow>
    </s:textFlow>
</s:RichEditableText>

并且您侦听整个文本组件上的 mouseOver 事件。

然后要测试鼠标是否位于图像上,请实现 mouseOver 处理程序:

private function toggleTooltip():void {
    var graphic:DisplayObject = myImg.graphic;
    var anchor:Point = graphic.localToGlobal(new Point(0, 0));

    if (mouseX >= anchor.x && mouseX <= anchor.x + graphic.width &&
        mouseY >= anchor.y && mouseY <= anchor.y + graphic.height) 
    {
        trace('show tooltip');
    }
    else {
        trace('hide tooltip');
    }
}

You can do some hit-testing when the mouse is over the textflow component.

Suppose you have some textflow like this:

<s:RichEditableText width="100%" height="100%" mouseOver="toggleTooltip()">
    <s:textFlow>
        <s:TextFlow>
            <s:p>
                <s:span>Some text before</s:span>
                <s:img id="myImg" source="myImg.png" />
                <s:span>Some text after</s:span>
            </s:p>
        </s:TextFlow>
    </s:textFlow>
</s:RichEditableText>

And you listen for mouseOver events on the entire textcomponent.

Then to test if the mouse is over your image, implement the mouseOver handler:

private function toggleTooltip():void {
    var graphic:DisplayObject = myImg.graphic;
    var anchor:Point = graphic.localToGlobal(new Point(0, 0));

    if (mouseX >= anchor.x && mouseX <= anchor.x + graphic.width &&
        mouseY >= anchor.y && mouseY <= anchor.y + graphic.height) 
    {
        trace('show tooltip');
    }
    else {
        trace('hide tooltip');
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文