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 ...
随机推荐
- 学习笔记:javascript body常用事件
Window 事件属性 针对 window 对象触发的事件(应用到 <body> 标签): 属性 值 描述 onafterprint script 文档打印之后运行的脚本. onbefor ...
- mysql中 date datetime time timestamp 的区别
MySQL中关于时间的数据类型:它们分别是 date.datetime.time.timestamp.year date :"yyyy-mm-dd" 日期 1000-01 ...
- Linux增加磁盘操作
首先,增加磁盘分为4个大步骤:1.插上硬盘:2.分区;3.格式化4.挂载,然后分别说说以上四步的具体事项和注意内容. 1.插上硬盘(本位以虚拟机为例) 新买来一块磁盘,把磁盘插到主板上.虚拟机中操作如 ...
- 在Windows中单机环境下创建RabbitMQ集群
本文根据:http://www.360doc.com/content/15/0312/17/20874412_454622619.shtml整理而来 RabbitMQ具有很好的消息传递性能,同时又是开 ...
- Jenkins 发布后自动创建git tag
为了便于项目中对发布的版本进行回滚,所以我们每次发布完成以后自动创建git tag. 1,创建一个Jenkins任务,命名成为push_tag_demo: 2,配置<源码管理>,这里配置比 ...
- 用python实现对图像的卷积(滤波)
之前在看卷积神经网络,很好奇卷积到底是什么,最后看到了这篇文章http://blog.csdn.net/zouxy09/article/details/49080029,讲得很清楚,这篇文章中提到了对 ...
- Day4-软件目录开发规范
层次清晰的目录结构:1. 可读性高: 不熟悉这个项目的代码的人,一眼就能看懂目录结构,知道程序启动脚本是哪个,测试目录在哪儿,配置文件在哪儿等等.从而非常快速的了解这个项目.2. 可维护性高: 定义好 ...
- 【WPF MaterialDesign 示例开源项目】 Work Time Manager
转岗写了将近一年的 PHP 最近因为 工作太多太杂, 在汇报工作的时候经常会忘记自己做了些什么,本来想只是使用excel来记录,但是发现了excel的很多局限性,光是无法共享就郁闷死了,习惯了下班不带 ...
- Swift 入门之简单语法(一)
定义 let 定义常量,一经赋值不允许再修改 var 定义变量,赋值之后仍然可以修改 //: # 常量 //: 定义常量并且直接设置数值 let x = 20 //: 常量数值一经设置,不能修改,以下 ...
- C语言之函数
函数:为了完成某一项功能而编写的代码的集合. C语言中的函数可以分为内置和自定函数. 内置函数:C语言中已经定义过的函数,不需要 声明,可以直接调用. 常见的内置函数: 函数名 类库 说明 doubl ...