Flex: How to call an actionscript function from htmlText anchor

元气小坏坏 提交于 2020-01-02 08:39:08

问题


Is there any way to call an action script function from an anchor which defined in TextArea component's htmlText property.

Thank you


回答1:


If this anchor is an href from an tag, you can dispatch events and handle them like that:

<mx:Script>
    <![CDATA[
        private function linkHandler(e:TextEvent):void
        {
            if (e.text == "test")
                trace("test called")
        }
    ]]>
</mx:Script>
<mx:creationComplete>
    <![CDATA[
        textArea.htmlText="<a href='event:test'>Link!</a>";
    ]]>
</mx:creationComplete>

<mx:TextArea id="textArea" link="linkHandler(event)" />  



回答2:


i got the answer here..




回答3:


The ExternalInterface class will provide you with a communication channel between Javascript and Actionscript. Using this class, you can listen for calls from the page's Javascript, as well as, dispatch messages and data back.

The links below are referencing AS 3.0. Hope that helps!

ExternalInterface Docmentation

Usage Description

Sample Code



来源:https://stackoverflow.com/questions/871325/flex-how-to-call-an-actionscript-function-from-htmltext-anchor

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!