当用户单击 TextField 中的超链接时,如何阻止 Flash 更改缩进?
我有一个 TextField,通过设置 htmlText 来初始化它。 文本具有锚标记(超链接)。 当用户单击超链接时,段落中第二行和后续行的缩进会发生变化。 为什么? 我该如何阻止它?
我的 html 在行的开头有一个图像,后面跟着标签,然后是更多文本。 为了将超链接设置为始终显示蓝色并在鼠标悬停在超链接上方时加下划线,我这样做:
var css:StyleSheet = new StyleSheet();
css.parseCSS("a {color: #0000FF;} a:hover {text-decoration: underline;}");
stepText.styleSheet = css;
stepText.htmlText = textToUse;
stepText.visible = true;
是 html 文本的片段(添加了换行符和 exrta 空格以提高可读性 - 最初它是一长行):
<textformat indent="-37" blockindent="37" >
<img src="media/interface/level-1-bullets/solid-circle.png"
align="left"
hspace="8"
vspace="1"/>
American Dental Association. (n.d.). <i>Cleaning your teeth and gums (oral hygiene)</i>.
Retrieved 11/24/08, from
<a href="http://www.ada.org/public/topics/cleaning_faq.asp"
target="_blank">http://www.ada.org/public/topics/cleaning_faq.asp
</a>
</textformat>
<br/>
这 事实证明,文本字段的宽度使其可以换行,并且第二行以“Retrieved 11/24/08”开头。 单击超链接会导致该特定行缩进。 后续段落不受影响。
旁白:该图像是一个大约 37 像素宽的列表项目符号。 (我使用图像而不是 li 标签,因为 Flash 不允许嵌套列表,所以我使用一系列具有不同数量空白的图像来伪造它来模拟三个级别的缩进。)
想法:我正在考虑更改所有超链接以使用“ event:”作为 URL 协议,这会导致触发 TextEvent.LINK 事件,而不是跟随链接。 然后我必须在第二次调用中打开浏览器。 我可以使用此事件处理程序将 html 文本设置为自身,这可能可以解决问题。 (当我在应用程序中切换页面然后返回到该页面时,一切都再次正常。)
问题:如果我使用“事件:”协议并且用户尝试单击鼠标右键,他们将收到错误,或者有人告诉我。 (请参阅 http ://www.blog.lessrain.com/as3-texteventlink-and-contextmenu-incompatibilities/)我不喜欢这种权衡。
I have a TextField which I initialize by setting htmlText.
The text has anchor tags (hyperlinks).
When a user clicks on the hyperlink, the indentation of the second and subsequent lines in the paragraph changes. Why? How do I stop it?
My html has an image at the beginning of the line, followed by the tag, followed by more text. To style the hyper links to look blue always and underlined when the mouse is over them, I do this:
var css:StyleSheet = new StyleSheet();
css.parseCSS("a {color: #0000FF;} a:hover {text-decoration: underline;}");
stepText.styleSheet = css;
stepText.htmlText = textToUse;
stepText.visible = true;
Here is a fragment of the html text (with newlines and exrta whitespace added to improve readability - originally it was one long line):
<textformat indent="-37" blockindent="37" >
<img src="media/interface/level-1-bullets/solid-circle.png"
align="left"
hspace="8"
vspace="1"/>
American Dental Association. (n.d.). <i>Cleaning your teeth and gums (oral hygiene)</i>.
Retrieved 11/24/08, from
<a href="http://www.ada.org/public/topics/cleaning_faq.asp"
target="_blank">http://www.ada.org/public/topics/cleaning_faq.asp
</a>
</textformat>
<br/>
As it turns out, the text field is of a width such that it wraps and the second line starts with "Retrieved 11/24/08". Clicking on the hyper link causes this particular line to be indented. Subsequent paragraphs are not affected.
ASIDE: The image is a list bullet about 37 pixels wide. (I used images instead of li tags because Flash does not allow nested lists, so I faked it using a series of images with varying amounts of whitespace to simulate three levels of indentation.)
IDEA: I was thinking of changing all hyperlinks to use "event:" as the URL protocol, which causes a TextEvent.LINK event to be triggered instead of following the link. Then I would have to open the browser in a second call. I could use this event handler to set the html text to itself, which might clear the problem. (When I switch pages in my application and then come back to the page, everything is OKAY again.)
PROBLEM: If I use the "event:" protocol and user tries the right-mouse button click, they will get an error, or so I am told. (See http://www.blog.lessrain.com/as3-texteventlink-and-contextmenu-incompatibilities/ ) I do not like this trade-off.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我找到了一个解决方法,按照我上面的想法。
1) 所有超链接均以“event:”作为前缀。
2) 在控件上添加事件监听器来处理请求。
3) 侦听器启动浏览器并将文本设置为空字符串,然后设置其原始值。
1)事件前缀:。
2) 添加事件监听器
3) 处理LINK 事件。
如果我不首先将该字段设置为空字符串,它不会认为发生任何更改,因此它不会执行任何操作。
I found a workaround, along the lines of my IDEA above.
1) Prefix all hyper-links with "event:".
2) Add an event listener on the control to process the request.
3) The listener launches the browser AND sets the text to empty string then its original value.
1) Prefixing with event:.
2) Add event listener
3) Handle the LINK event.
If I don't set the field to empty string first it does not think anything changed, so it does nothing.