我我已經解決了這個我自己的問題:D
以上機制的區別在於getFlexApp()函數,它提供了想方設法得到flex對象。一旦它得到對象,我只需調用EIButtonClicked()函數,並將值傳遞給它。
function getFlexApp(appName) {
if (navigator.appName.indexOf ("Microsoft") !=-1) {
return window.top[appName];
} else {
return window.top.document[appName];
}
}
function callFlexFunction() {
var sTxt ;
sTxt = document.getElementById('txt1').value;
alert('HTML/Javascript wants to tell you about ' + sTxt);
getFlexApp('iframeCommTest').EIButtonClicked(sTxt) ;
}
同時,flex側建立了外部接口回調。您可以看到上面JS中引用的「EIButtonClicked」與下面AS中的回調標籤相匹配。
/**
* When the button is clicked.
*/
public function onEIButtonClicked(data:String):void {
Alert.show("Flash wants to tell you about " + data);
}
protected function application1_creationCompleteHandler():void {
// TODO Auto-generated method stub
if (ExternalInterface.available) {
ExternalInterface.addCallback("EIButtonClicked", onEIButtonClicked);
}
}