FLEX:如何捕捉“a href"事件 [英] FLEX:How to catch 'a href' event

查看:24
本文介绍了FLEX:如何捕捉“a href"事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将数据从 TextFlow 加载到 spark:TextArea.在 TextFlow 中,我有 'a href' 元素.问题在于链接"元素的地址.他们中的一些人会离开页面(这些我会离开而不做任何事情),其他人会去我网站的其他子页面(这些我必须在代码中捕获和处理).

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"> 

我可以在旧的 mx:TextArea 中在 link:event 上捕获事件,但我不能在这里执行此操作.我尝试手动添加:

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)

但它不起作用.当我更改为捕获 MOUSE_CLICK 事件时,我正在捕获该事件,但无法解析它以获取所需的地址.

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.

有人知道怎么做吗?我不必坚持使用 TextArea,但组件必须从 TextFlow 下载内容.

Anybody have idea how to do it? I doesnt have to stick with TextArea, but component have to download content form TextFlow.

PS 我注意到当我将 event:page_adress 添加到a href"时,链接停止工作(这意味着它可能开始抛出事件),但我无法捕捉到它...

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 是使用

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 在点击链接后不运行...

myClickHandler doesnt run after clicking on link...

推荐答案

好的,我在这个博客上找到了答案:http://flexdevtips.blogspot.com/2010/10/displaying-html-text-in-labels.html

OK i found answer on this blog: http://flexdevtips.blogspot.com/2010/10/displaying-html-text-in-labels.html

基本上我必须搜索整个 textFlow 并在创建链接的情况下 - 手动添加事件.

Bassicly i had to search whole textFlow and in case of founding a Link - adding manually Event to it.

我发布了我的代码,以防 flexdevtips 博客将来可能会关闭:

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);
}

其中 tt 是我导入 textFlow 的 textarea

where tt is my textarea with imported textFlow

这篇关于FLEX:如何捕捉“a href"事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆