Flash TextField selectable bug block TextEvent.Link solution
There is an old version Felx SDK bug(in my case it's Flex SDK v3.3.0.4852) that when TextField.selectable is set to false, link event on the textfield will be blocked. So if you have added html text including a link into the textfield, e.g.:
var textField:TextField = new TextField();
textField.htmlText = "This is a testing message. <a href='event:clickHandler'>Click</a> to see more.";
textField.selectable = false;
Then when you click "Click", it will not trigger "clickHandler" function. This will also happen when the anchor's href value is a URL, e.g.:
var textField:TextField = new TextField();
textField.htmlText = "This is a testing message. <a href='http://www.google.com' target='_blank'>Click</a> to see more.";
textField.selectable = false;
When click "Click", browser will not open the Google page in a new tab. But you can actually right click on the link and select "Open" to open it.
The previous two situations are both caused by selectable property set to false using Flex SDK 3.3.0.4852. I have three solutions to fix this:
The first two solutions are simple, I'll give some more details on the third solution which will not change selectable attribute nor SDK. The main idea is register MouseClick event on the textfield, when user click the text, check whether the position is on the link. If the mouse click is on the link text, use "navigateToURL" function to open the link.
1. New a TextField object and set accordingly:
var textField:TextField = new TextField();
textField.htmlText = "Testing message. <a href='http://www.google.com' target='_blank'>Click</a> to see more.";
textField.selectable = false;
var textFmtLink:TextFormat = new TextFormat();
formatter.color = "0x3366BB";
formatter.underline = true;
2. Use "formatFieldLinkText" function to formate the link text and register event listener to handle click event:
formatFieldLinkText(textField, textFmtLink); protected function formatFieldLinkText(textField:TextField, linkFormat:TextFormat):void
{
var fieldText:String = textField.text;
var textFormat:TextFormat = textField.getTextFormat();
var formatedText:String = "";
var linkObjArray:Array = []; var textArray:Array = fieldText.split(/(<a\s[^>]+>.+?<\/a>)/gi );
var linkTextPattern:RegExp = new RegExp("(?i)[^>]*(?=</a>)" );
var linkUrlPattern:RegExp = /href\s*=\s*['"]([^'"]+)['"]/i;
var linkTargetPattern:RegExp = /target\s*=\s*['"]([^'"]+)['"]/i ;
for (var i:int = 0; i < textArray.length; i++)
{
//plain text
if (textArray[i].toString().search(/(<a\s[^>]+>.+?<\/a>)/gi )==-1)
{
formatedText+=textArray[i].toString();
continue;
} var linkText:String = linkTextPattern.exec(textArray[i]);
// check if linkText is blank
if (isBlank(linkText))
{
return;
}
var linkUrl:Array = linkUrlPattern.exec(textArray[i]);
var linkTarget:Array = linkTargetPattern.exec(textArray[i]);
if (linkUrl==null)
{
return;
}
var linkObj:Object = new Object();
linkObj.href = linkUrl== null?"" :linkUrl[1];
linkObj.target = linkTarget== null?"" :linkTarget[1];
linkObj.linkBegin = formatedText.length;
linkObj.linkEnd = formatedText.length + linkText.length;
linkObjArray.push(linkObj); formatedText+=linkText; textField.addEventListener(MouseEvent.CLICK, hyperLinkClicked);
}
textField.text = formatedText;
textField.setTextFormat(textFormat);
for (var j:int = 0; j < linkObjArray.length; j++)
{
textField.setTextFormat(linkFormat, linkObjArray[j].linkBegin, linkObjArray[j].linkEnd);
} var href:String = "";
var target:String = "";
function hyperLinkClicked (e:MouseEvent):void
{
var idx:int = e.currentTarget.getCharIndexAtPoint(e.localX, e.localY);
if (posOnLink(idx))
{
var request:URLRequest = new URLRequest(href);
navigateToURL(request, target);
}
} // can optimize the search method
function posOnLink(idx:int):Boolean
{
for (var k:int = 0; k < linkObjArray.length; k++)
{
if (idx >= linkObjArray[k].linkBegin && idx < linkObjArray[k].linkEnd)
{
href = linkObjArray[k].href;
target = linkObjArray[k].target;
return true ;
}
}
return false ;
}
}
(本文系从原博客迁移至此,并进行部分编辑。原文链接:http://thewaychung.iteye.com/blog/1974209)
Flash TextField selectable bug block TextEvent.Link solution的更多相关文章
- event duplication bind bug & h5 dataset flag solution
event duplication bind bug & h5 dataset flag solution https://codepen.io/xgqfrms/full/PaRBEy/ OK ...
- [bug] VS2013 Brower Link和Aspnetpager引发的问题分析
概述 在ie11上浏览页面的时候,突然发现在使用Aspnetpager的页面会有一个bug. 开发环境:win8.1+vs2013+ie11. 项目描述:这个问题出现在内容页中,应用了母版页. 解决方 ...
- Flask Bug记录之The innermost block that needs to be closed is 'block'.
源码 <!DOCTYPE html> <title>{% block title %}{% endblock title %} - Flask</title> &l ...
- 【转】关于FLASH中图文混排聊天框的小结
原文链接 图文混排也是FLASH里一个很古老的话题了,我们不像美国佬那样游戏里面聊天框就是聊天框,全是文字干干净净,也不像日本人发明了并且频繁地使用颜文字.不管是做论坛.做游戏,必定要实现的一点就是带 ...
- nand flash详解及驱动编写
https://www.crifan.com/files/doc/docbook/linux_nand_driver/release/html/linux_nand_driver.html#nand_ ...
- WinCE NAND flash - FAL
http://blog.csdn.net/renpine/article/details/4572347 http://msdn.microsoft.com/en-US/library/ee48203 ...
- Flash 无法输入中文的修正方法
在某些运行模式或运行时环境中,Flash 有一个 Bug,文本框与键盘的交互模式会无法输入中文(包括日文等带有输入法状态栏的输入模式),只要对 TextField 文本框实例的 FocusEvent. ...
- flask模板应用-消息闪现(flash())
消息闪现 flask提供了一个非常有用的flash()函数,它可以用来“闪现”需要提示给用户的消息,比如当用户登录成功后显示“欢迎回来!”.在视图函数调用flash()函数,传入消息内容,flash( ...
- python tornado 中使用 flash消息闪现
1.html 中引入文件 {% block head %} <link href="/static/common/sweetalert/sweetalert.css" rel ...
随机推荐
- zabbix_server表面启动成功,但是没有进程
[root@iZ25m1box8cZ zabbix]# /etc/init.d/zabbix_server start Starting zabbix_server (via systemctl): ...
- 解决xmapp中Apache端口号占用问题
[原]解决 "安装xmapp后Apache不能正常启动" 问题 小伙伴们安装xmapp后发现Apache不能正常开启,下面给出了不同情况的解决办法,可以分为以下几种情况分析问题: ...
- cd命令使用详解
cd命令是目录切换命令,是shell内置命令. 语法: cd [-L|-P] [dir] 选项: -p 如果要切换到的目标目录是一个符号连接,直接切换到符号连接指向的目标目录 -L 如果要切换的目标目 ...
- Arcengine 二次开发添加右键菜单
最近在搞arcengine 二次开发,遇到了好多问题,也通过网上查资料试着慢慢解决了,把解决的步骤记录下来,有需要帮助的可以看一下,也欢迎各位来批评指正. 想给自己的map application在图 ...
- Java IO和NIO文章目录
1.java IO详尽解析 2.深入分析 Java I/O 的工作机制 3.InputStream类详解 4.OutputStream类详解 5.JAVA的节点流和处理流 6.FileInputStr ...
- 【JAVAWEB学习笔记】06_jQuery基础
接05的学习笔记. 四.使用JQ完成省市二级联动 1.需求分析 使用jquery完成省市二级联动 2.技术分析 2.1数组的遍历操作 方式一: $(function(){ // 全选/ 全不选 $(& ...
- Java学习笔记——Linux下安装配置MySQL
山重水复疑无路,柳暗花明又一村 --游山西村 系统:Ubuntu 16.04LTS 1\官网下载mysql-5.7.18-linux-glibc2.5-x86_64.tar.gz2\建立工作组:$su ...
- Spring Cloud 注册中心Eureka
一.简介 最近在看Spring Cloud微服务,接下来的时间和大家一起分享我所看到的,公司现在用的是dubbo ,之后有时间也去了解了解dubbo的源码.与dubbo相比较,Spring Cloud ...
- Day2-字符编码转换
1.在python2默认编码是ASCII, python3里默认是unicode 2.unicode 分为 utf-32(占4个字节),utf-16(占两个字节),utf-8(占1-4个字节), so ...
- c++ 自动应用类型转换
c++中,在赋值时如果类型不匹配,就会应用到:类型转换.类型转换又分为隐式转换(implicit conversion) 和 显式强制类型转换(emplcit conversion).在这我围绕着类的 ...