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. ER模型的学习

    (计应154兰家才)在建立表后开始了学习的第一步,了解数据库的基本知识,就以建立bbs论坛为标准学习er模型,首先建立了4个表分别是BBSReply,BBSSection,BBSTopic,BBSUs ...

  2. JVM类加载续

    上一篇理解了JVM类加载过程的第一个阶段,这篇来说说剩下的阶段:验证.准备.解析.初始化.需要注意的是,这些阶段(解析除外)只是按照这个顺序开始,但是执行的过程中可能存在交叉. 验证:就是要对加载的二 ...

  3. Day2-列表、字符串、字典、集合

    一.列表 定义列表:通过下标访问列表中的内容,从0开始 >>> name = ["zhang","wang","li",& ...

  4. 【干货】Markdown编辑博文,公式图片轻松搞定

    # Markdown 使用操作手册 作者:白宁超 Blog:伏草唯存 Markdown 是一种轻量级的「标记语言」,它的优点很多,目前也被越来越多的写作爱好者,撰稿者广泛使用.看到这里请不要被「标记」 ...

  5. zabbix agent安装详解

    安装 Installing repository configuration package Zabbix 2.2 for RHEL5, Oracle Linux 5, CentOS 5: rpm - ...

  6. centos6.5 修改java环境变量

    [root@m1 ~]# cat /etc/profile export JAVA_HOME=/usr/local/soft/jdkexport PATH=$JAVA_HOME/bin:$PATH e ...

  7. iOS 原生模块 给 Javascript(ReactNative) 发送事件 (通知监听)

    官方中文文档是这样描述的:   就给我们这几句话 就打发我们了. 按照上面的写法,根本不知道  - (void)calendarEventReminderReceived:(NSNotificatio ...

  8. SQL Server 中函数的理解总结

    T-SQL语言为我们提供了更加灵活的方式操作数据,那就是函数,函数总的分为三大类:标量函数:(传入一个参数,再传出一个参数)聚合函数(传入多个参数,传出一个参数),表值函数(传入一个结果集对象,让我们 ...

  9. 两强相争,鹿死谁手 — JQuery中的Ajax与AngularJS中的$http

    一.JQuery与AngularJS 首先,先简单的了解一下JQuery与AngularJS.从源头上来说,两者都属于原生JS所封装成的库,两种为平行关系. 二.Ajax请求与数据遍历打印 这里是Aj ...

  10. Vue单页式应用(Hash模式下)实现微信分享

    前端微信分享的基本步骤: 一.绑定域名: 先登录微信公众平台进入"公众号设置"的"功能设置"里填写"JS接口安全域名".这个不多说,微信开发 ...