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 ...
随机推荐
- 记事本app TOP5(个人观点)
1.为知笔记 为知笔记定位于高效率工作笔记,主打工作笔记的移动应用,是目前国内唯一一款"工作笔记"的云笔记类产品.除了常用的笔记功能保存的网页.灵感笔记.重要文档.照片.便签等,为 ...
- [笔记]我的Linux入门之路 - 05.Eclipse的Python开发环境搭建与Numpy、Scipy库安装
一.Python环境 直接终端查询下python安装没:python --version Python 2.7.12 Ubuntu竟然已经装了Python2.7,那就好说了.不然自己装和装jdk差不多 ...
- JAVA并发编程实战---第三章:对象的共享(2)
线程封闭 如果仅仅在单线程内访问数据,就不需要同步,这种技术被称为线程封闭,它是实现线程安全性的最简单的方式之一.当某个对象封闭在一个线程中时,这种方法将自动实现线程安全性,即使被封闭的对象本生不是线 ...
- 连锁反应confirm
<script> function del(){ var flag = confirm("你真要删除么?"); if( flag ){ alert("我已被你 ...
- ucenter 单点登录,终极版
一 ,discuz ecshop 两边登陆都可以同步登陆到另一程序上,但退出则无法实现同步登陆.顺着 Ecshop 的退出流程,顺藤摸瓜找到了 lib_common.php 文件中的 uc_ca ...
- 使用NetronGraphLib类库开发Qfd质量屋编制工具
前言 可执行文件下载 QfdHouse-exe.zip 因项目需要做了一个质量功能配置(Quality Function Deployment 简称Qfd)的质量屋编制工具软件,本软件是在发布一个免费 ...
- Kotlin学习第一课:从对比Java开始
1. 介绍 今年初,甲骨文再次对谷歌所谓的安卓侵权使用Java提起诉讼,要求后者赔偿高达90亿美元.随后便传出谷歌因此计划将主力语言切换到苹果主导的Swift,不过这事后来没了跟进. 但谷歌在这两天的 ...
- .Net程序员学用Oracle系列(29):PLSQL 之批量应用和系统包
1.批量数据操作 1.1.批量生成数据 1.2.批量插入数据 2.批量生成脚本 3.生成数据字典 4.常见系统包 4.1.DBMS_OUTPUT 4.2.DBMS_RANDOM 4.3.其它系统包及常 ...
- 如何选择版本控制系统之二---Git的研发应用场
之前写了一篇<如何选择版本控制系统 ---为什么选择Git版本控制系统>,地址是:http://www.cnblogs.com/goldenfish/p/6876864.html,有兴趣的 ...
- JDBC与JNDI的区别
程序员开发时,知道要开发访问MySQL数据库的应用,于是将一个对 MySQL JDBC 驱动程序类的引用进行了编码,并通过使用适当的 JDBC URL 连接到数据库. 就像以下代码这样: Connec ...