FLEX:如何捕获“href”事件 [英] FLEX:How to catch 'a href' event
问题描述
我正在将数据从TextFlow加载到spark:TextArea。在TextFlow中我有一个href元素。问题在于链接元素的地址。其中一些将会出现在页面之外(这些我将离开而不做任何事情),其他的会去我的网站的其他子页面(这些我必须在代码中捕获和处理)。
我计划抓住点击链接事件来决定要做什么,但我不能这样做。我通过写作读到
< a href =event:page_adress>
我可以捕获链接上的事件:旧的mx:TextArea中的事件,但我不能这样做。我试图手动添加:
addEventListener(TextEvent.Link,functionName)
/ pre>
但它不工作。
当我改变为捕捉MOUSE_CLICK事件时,我捕捉事件,但不能解析它来获取所需的地址。
任何人都有想法如何做?我不必坚持TextArea,但组件必须下载TextFlow的内容。
PS我注意到,当我添加事件:page_adress到a href链接停止工作(这意味着它可能开始投掷事件),但我无法抓住它...
PS2 TextFlow是从外部数据库导入的,
TextFlowUtil.importFromXML
i尝试使用链接元素,点击事件,但它不起作用:
< a click =myClickHandler(event)>
点击链接后myClickHandler不运行...
解决方案OK我在这个博客上找到答案: http://flexdevtips.blogspot.com/2010/10/displaying-html-text-in-labels.html
bassicly我不得不搜索整个textFlow,如果创建一个链接 - 手动添加事件。
我发布我的代码,以防flexdevtips博客可能将来会下降:
/ **
*递归查找第一个LinkElement并返回。
* /
私有函数findLinkElement(group:FlowGroupElement):void
{
var childGroups:Array = [];
//首先检查当前组的所有子元素,
//还可以保存任何FlowGroupElement
的子项(var i:int = 0; i< group.numChildren; i ++){
var element:FlowElement = group.getChildAt(i);
if(element为LinkElement)
{
linksArray.push(元素为LinkElement);
} else if(元素为FlowGroupElement)
{
childGroups.push(element);
}
}
//递归检查子组件FlowGroupElements $($ i $) = childGroups [i];
findLinkElement(childGroup);
}
}
我不得不使用它我的代码如下:
linksArray = [];
findLinkElement(tt.textFlow);
var iter:int = 0;
for(iter = 0; iter< linksArray.length; iter ++)
{
linksArray [iter] .addEventListener(FlowElementMouseEvent.MOUSE_DOWN,linkSelect,false,0,true)
}
其中tt是我的textarea与导入的textFlow
I'm loading data from TextFlow to spark:TextArea. In TextFlow i have 'a href' elements. Problem lies with the address of the 'link' elements. Some of them will go outside of the page (these i will leave without doing anything), other will go to other subpages in my site(these one i have to catch and process in code).
I planned on catching 'clicking on link' event to decide what to do, but i can't do this. I read that by writing
<a href="event:page_adress">
i could catch the event on link:event in old mx:TextArea, but i cant do this here. I tried to manualy add:
addEventListener(TextEvent.Link, functionName)
but it doesnt work. When i change to catching MOUSE_CLICK event i'm catching the event, but cant parse it to get the needed address.
Anybody have idea how to do it? I doesnt have to stick with TextArea, but component have to download content form TextFlow.
PS I noticed that when i added event:page_adress to the 'a href' the link stopped working (that means it probably started throwing events), but i cant catch it...
PS2 TextFlow is imported from external database with
TextFlowUtil.importFromXML
i tried using in link element, click event but it doesnt work:
<a click="myClickHandler(event)">
myClickHandler doesnt run after clicking on link...
解决方案OK i found answer on this blog: http://flexdevtips.blogspot.com/2010/10/displaying-html-text-in-labels.html
Bassicly i had to search whole textFlow and in case of founding a Link - adding manually Event to it.
Im posting my code in case that the flexdevtips blog might be down in the future:
/** * Finds the first LinkElement recursively and returns it. */ private function findLinkElement(group:FlowGroupElement):void { var childGroups:Array = []; // First check all the child elements of the current group, // Also save any children that are FlowGroupElement for (var i:int = 0; i < group.numChildren; i++) { var element:FlowElement = group.getChildAt(i); if (element is LinkElement) { linksArray.push(element as LinkElement); } else if (element is FlowGroupElement) { childGroups.push(element); } } // Recursively check the child FlowGroupElements now for (i = 0; i < childGroups.length; i++) { var childGroup:FlowGroupElement = childGroups[i]; findLinkElement(childGroup); } }
and i had to use it in my code like this:
linksArray = []; findLinkElement(tt.textFlow); var iter:int=0; for (iter = 0 ; iter<linksArray.length ; iter++) { linksArray[iter].addEventListener(FlowElementMouseEvent.MOUSE_DOWN,linkSelect, false, 0, true); }
where tt is my textarea with imported textFlow
这篇关于FLEX:如何捕获“href”事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!