Pay for Hesitation: 在mxml中呼叫javascript function

Pages

2008年3月12日 星期三

在mxml中呼叫javascript function

早安~ 晨型人, 昨天寫了prefuse和jung的converter太高興, 所以12:30才睡 orz, 睡到快8點 ~"~

在mxml中呼叫javascript的函式主要透過ExternalInterface class, 直接看run例子吧~

main.mxml --------------------------
private function callJavaScript():void {
if(ExternalInterface.available) {
ExternalInterface.call("sayHelloWorld");
} else {
Alert.show("ExternalInterface is not available");
}
}
<mx:Button label="Say 'Hello World'" click="callJavaScript();" />

HTML document ------------------------
<script language="JavaScript" type="text/javascript">
function sayHelloWorld() {
alert("Hello World, from JavaScript");
}
</script>
先用ExternalInterface.available確認你的flex是否支援外部介面.
這邊所指的html通常是編輯/html-template/下面的index.template.html
我想這樣就應該可以讓user點擊認證信中html的url, 將id和mail透過javascript傳給swf了~

沒有留言: