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:

1. Set selectable to true;
2. Change Flex SDK to newly version;
3. Register event listener to handle click event;

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的更多相关文章

  1. event duplication bind bug & h5 dataset flag solution

    event duplication bind bug & h5 dataset flag solution https://codepen.io/xgqfrms/full/PaRBEy/ OK ...

  2. [bug] VS2013 Brower Link和Aspnetpager引发的问题分析

    概述 在ie11上浏览页面的时候,突然发现在使用Aspnetpager的页面会有一个bug. 开发环境:win8.1+vs2013+ie11. 项目描述:这个问题出现在内容页中,应用了母版页. 解决方 ...

  3. Flask Bug记录之The innermost block that needs to be closed is 'block'.

    源码 <!DOCTYPE html> <title>{% block title %}{% endblock title %} - Flask</title> &l ...

  4. 【转】关于FLASH中图文混排聊天框的小结

    原文链接 图文混排也是FLASH里一个很古老的话题了,我们不像美国佬那样游戏里面聊天框就是聊天框,全是文字干干净净,也不像日本人发明了并且频繁地使用颜文字.不管是做论坛.做游戏,必定要实现的一点就是带 ...

  5. nand flash详解及驱动编写

    https://www.crifan.com/files/doc/docbook/linux_nand_driver/release/html/linux_nand_driver.html#nand_ ...

  6. WinCE NAND flash - FAL

    http://blog.csdn.net/renpine/article/details/4572347 http://msdn.microsoft.com/en-US/library/ee48203 ...

  7. Flash 无法输入中文的修正方法

    在某些运行模式或运行时环境中,Flash 有一个 Bug,文本框与键盘的交互模式会无法输入中文(包括日文等带有输入法状态栏的输入模式),只要对 TextField 文本框实例的 FocusEvent. ...

  8. flask模板应用-消息闪现(flash())

    消息闪现 flask提供了一个非常有用的flash()函数,它可以用来“闪现”需要提示给用户的消息,比如当用户登录成功后显示“欢迎回来!”.在视图函数调用flash()函数,传入消息内容,flash( ...

  9. python tornado 中使用 flash消息闪现

    1.html 中引入文件 {% block head %} <link href="/static/common/sweetalert/sweetalert.css" rel ...

随机推荐

  1. JS中对于prototype的理解

    JS中的prototype是JS中比较难理解的一个部分 本文基于下面几个知识点: 1 原型法设计模式 在.Net中可以使用clone()来实现原型法 原型法的主要思想是,现在有1个类A,我想要创建一个 ...

  2. poj 1001 分析

    1) n = 0; return 1: 2) n = 1; bool standardizeNumNoDot(string &s){标准化是一定要得} _将‘.’前后的〇全部去除,正常retu ...

  3. win10 64位下装Virtual Box安装Linux(centOS)配置联网

    第一步:安装VritualBox 百度"VritualBox"下载安装即可: 第二步:下载Linux镜像系统并安装 这里写出我参照的博客,很详细,我就不累赘了! 原文地址:http ...

  4. hadoop集群中客户端修改、删除文件失败

    这是因为hadoop集群在启动时自动进入安全模式 查看安全模式状态:hadoop fs –safemode get 进入安全模式状态:hadoop fs –safemode enter 退出安全模式状 ...

  5. hdu1420 Prepared for New Acmer 简单数学

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1420 简单数学题 第一次wa在可能和会出现取模后值为负数的情况. 只要会一个数论上的简单公式(a*b) ...

  6. Java学习笔记——排序算法之快速排序

    会当凌绝顶,一览众山小. --望岳 如果说有哪个排序算法不能不会,那就是快速排序(Quick Sort)了 快速排序简单而高效,是最适合学习的进阶排序算法. 直接上代码: public class Q ...

  7. Vue声明式渲染

    Vue.js 的核心是一个允许采用简洁的模板语法来声明式的将数据渲染进 DOM,也就是将模板中的文本数据写进DOM中,使用  {{data}}  的格式写入.此代码都是Vue.js官网上的实例. 1. ...

  8. 分享一个完整的Mybatis分页解决方案

    Mybatis 的物理分页是应用中的一个难点,特别是配合检索和排序功能叠加时更是如此. 我在最近的项目中开发了这个通用分页器,过程中参考了站内不少好文章,阅读源码帮助更大minglisoft.cn/t ...

  9. php原生curl接口的请求

    /** * @desc 接口请求处理 * @date 2017/5/19 11:39 * @param [$url请求的接口地址,$way为false为get请求,true为post请求] * @au ...

  10. Akka(3): Actor监管 - 细述BackoffSupervisor

    在上一篇讨论中我们谈到了监管:在Akka中就是一种直属父子监管树结构,父级Actor负责处理直属子级Actor产生的异常.当时我们把BackoffSupervisor作为父子监管方式的其中一种.实际上 ...