从动态文本AS3函数调用 [英] AS3 function call from dynamic textfield

查看:222
本文介绍了从动态文本AS3函数调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从一个动态文本调用AS3函数

我已经试过这样:

 函数showPopupWindow(){
    跟踪(它的工作原理);
}

VAR文字=世界,你好< A HREF =#的onclick ='showPopupWindow()'>< U>这是一个函数调用< / U>< / A>中;

text_txt.htmlText =文本;
 

解决方案

您将不得不使用 TextEvent.LINK 事件。首先,你需要创建一个指向一个链接到一个URL的Flash可以通过prepending 事件承认:来命名。例如,你可能有一段文字是这样的:

  textField.htmlText =< A HREF =事件:的playMovie'>玩< / A>< BR />。 +
                     < A HREF =事件:stopMovie。>停止< / A>中;
 

然后,你需要添加一个监听事件。您可以使用 TextEvent,并将::文属性,以确定哪些链接被点击。使用上面的code,这里有一个样品处理:

  textField.addEventListener(TextEvent.LINK,handleLink);

功能handleLink(EVT:TextEvent,并将):无效{
    开关(evt.text){
        案的playMovie:
            玩();
            打破;
        案stopMovie:
            停止();
            打破;
    }
}
 

I'm trying to call an as3 function from a dynamic textfield.

I've tried this:

function showPopupWindow(){
    trace("it works");
}

var texts="Hello world. <a href='#' onclick='showPopupWindow()'><u>This is a function call</u></a>";

text_txt.htmlText = texts;

解决方案

You'll have to use the TextEvent.LINK event. First, you'll need to create a link that points to a URL Flash can recognize by prepending event: to a name. For example, you might have a piece of text like this:

textField.htmlText = "<a href='event:playMovie'>Play.</a><br />" + 
                     "<a href='event:stopMovie'>Stop.</a>";

Then, you need to add a listener for the event. You can use the TextEvent::text property to determine what link was clicked. Using the above code, here's a sample handler:

textField.addEventListener(TextEvent.LINK, handleLink);

function handleLink(evt:TextEvent):void {
    switch (evt.text) {
        case "playMovie":
            play();
            break;
        case "stopMovie":
            stop();
            break;
    }
}

这篇关于从动态文本AS3函数调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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