查找文本组件(Flex/Actionscript)中鼠标悬停的单词
是否有可能(如果可以的话如何)找出当光标/鼠标移动到 << 时,光标/鼠标位于哪个单词上? mx:文本> 成分? 因此,例如,当用户沿着句子(在文本组件内)移动鼠标时,每个单词都会随着移动而突出显示(我知道您可以在按下鼠标按钮时突出显示 - 但这不是我希望的方式)。
感谢您提供任何信息。
Is it possible (if so how) to find out what word the cursor/mouse is over when it is moving over a < mx:Text > component?
So for example as the user moves the mouse along a sentence (inside text component), each word will highlight as they go (I know you can highlight while pressing the mouse button down - but that not how I wish to do it).
Thanks for any info.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
一种方法是:您需要创建自己的组件来扩展 mx:Text 组件。 我在这个例子中使用了
MyText
。 下面是MyText
的完整代码:它的工作原理是访问 Text 组件内的 TextField 对象的方法,查找鼠标坐标下的字符索引,然后查找该字符所属的单词。 这是一个简单的示例,您可能需要使其更加复杂以供实际使用。
Here's one way to do it: you need to create your own component that extends the mx:Text component. I used
MyText
in this example. Here's the full code forMyText
:It works by accessing methods of the TextField object inside the Text component, finding the character index under the mouse coordinates and then finding the word the character belongs to. This is a quick example, you probably need to make it more elaborate for real world use.
您需要使用 TextSnapshot 类。 您可以从文本控件的 textSnapshot 属性中获取它。 TextSnapshot 有一个 hitTestTextNearPos() 函数,您可以使用它来确定用户的鼠标靠近哪个字符。
不确定你想如何处理开始选择,但类似的东西应该可以工作。
You need to use the TextSnapshot class. You can grab it from your text control from the textSnapshot property. TextSnapshot has a hitTestTextNearPos() function that you can use to determine which character the user's mouse is near.
Not sure how you want to handle starting the selection, but something like that should work.