2012-07-30 47 views
2

我正在嘗試從動態文本字段調用as3函數。來自動態文本字段的AS3函數調用

我已經試過這樣:

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; 
+0

的可能重複[軟硬度:如何從呼叫錨的htmlText ActionScript函數(http://stackoverflow.com/questions/871325/flex-how-to -call-AN-ActionScript的功能從 - 的htmlText錨) – shaunhusain 2012-07-30 22:40:46

回答

5

你將不得不使用TextEvent.LINK事件。首先,您需要創建一個指向Flash名稱前綴event:以識別URL的鏈接。例如,你可能有這樣一段文字:

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

然後,您需要爲該事件添加一個偵聽器。您可以使用TextEvent::text屬性來確定單擊了哪個鏈接。使用上面的代碼,這裏有一個樣品處理:

textField.addEventListener(TextEvent.LINK, handleLink); 

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