2010-08-26 48 views
0

我試圖讓IFrameCommTest示例(from the Flex-IFrame site)在Flex 4中工作,並且,雖然IFrame本身工作,但通信不會。特別是,我需要從包含HTML頁面的Flex應用程序調用函數(我已經有一種方法可以讓Flex應用程序與HTML進行通信)。Flex-IFrame通信測試不工作

我已經exported the project,以方便您的幫助。

我懷疑問題是「parent.FABridge」不存在。我的猜測是flex4中的某些東西在DOM中的位置發生了變化。

(這篇文章是涉及到有關FABridge較早post

我認爲這將是問題的一個更清晰的例子。)

感謝,

布賴恩

回答

0

我我已經解決了這個我自己的問題: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); 
    } 
}