我有一个Flex应用程序,顶部有一个iframe。
我想通过javascript来调用iframe来调用。
到目前为止,我已经尝试过这个:
这是包含嵌入ROOT文档中的swf的对象
<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
id="IPRS_Dispatcher" width="1400" height="1000"
codebase="http://fpdownload.macromedia.com/get/flashplayer/current/swflash.cab">
<param name="movie" value="DispatcherMain.swf" />
<param name="quality" value="high" />
<!-- <param name="bgcolor" value="${bgcolor}" /> -->
<param name="allowScriptAccess" value="sameDomain" />
<param name='flashVars' value='strLang=english&strIPRSSrvHost=&strGPSSrvHost=192.168.1.130&strGPSSrvSoapPort=8081&strGPSSrvFwdPort=26000&strLoginMode=simple&strSOSSrvHost=192.168.1.80&strSOSSrvSoapPort=8082&strSOSSrvFwdPort=26001&strSOSLoginMode=simple&strUserSIP=&strUserPswd=&nDelayForMapReadySecs=10&nGPSUpdatesRateSecs=120&nGPSSubscriptionsIntervalMinutes=10&nLat=35.0&nLng=32.5&nZoomLevel=5&strClientServiceVersion=2.1.36.19&nPathDotsSize=1&nPathWidth=5&bHideAnnounce=false&bHideEmergencyPan=true&strMapMarkerLabelMode=name&key=ABQIAAAAYbXZyR09wFj6QsiYucHpGxQEO34WZEWuIFq1A7yobGXPE-K5exQV9ZYR6NIkF8LCR8wsYvlhOIYsfA' />
<embed id="IPRS_Dispatcher2" src="DispatcherMain.swf"
flashVars='strLang=english&strIPRSSrvHost=&strGPSSrvHost=192.168.1.130&strGPSSrvSoapPort=8081&strGPSSrvFwdPort=26000&strLoginMode=simple&strSOSSrvHost=192.168.1.80&strSOSSrvSoapPort=8082&strSOSSrvFwdPort=26001&strSOSLoginMode=simple&strUserSIP=&strUserPswd=&nDelayForMapReadySecs=10&nGPSUpdatesRateSecs=120&nGPSSubscriptionsIntervalMinutes=10&nLat=35.0&nLng=32.5&nZoomLevel=5&strClientServiceVersion=2.1.36.19&nPathDotsSize=1&nPathWidth=5&bHideAnnounce=false&bHideEmergencyPan=true&strMapMarkerLabelMode=name&key=ABQIAAAAYbXZyR09wFj6QsiYucHpGxQEO34WZEWuIFq1A7yobGXPE-K5exQV9ZYR6NIkF8LCR8wsYvlhOIYsfA'
width="1400" height="1000" name="IPRS_Dispatcher" align="middle"
play="true"
loop="false"
quality="high"
allowScriptAccess="sameDomain"
type="application/x-shockwave-flash"
pluginspage="http://www.adobe.com/go/getflashplayer"> <!-- bgcolor="${bgcolor}" -->
</embed>
</object>
我为我想要公开的功能添加了addcallback
ExternalInterface.addCallback("sendToFlash", callFromJavaScript);
FYI
public function callFromJavaScript(str):void
{
LogAddItem( 30, str);
}
在我的IFRAME中,我添加了功能
function callToFlash(str)
{
var swf = parent.top.$("#IPRS_Dispatcher");
var bool = swf.sendToFlash(str);
}
现在获取chrome中的错误 - 未捕获TypeError:对象[object Object]没有方法'sendToFlash'
更新25/06/2012 - 来自 console.log(swf)的输出
[
<embed src="DispatcherMain.swf" width="100%" height="100%" align="middle" id="IPRS_Dispatcher" quality="high" name="IPRS_Dispatcher" wmode="opaque" allowfullscreen="true" allowscriptaccess="always" pluginspage="http://www.adobe.com/go/getflashplayer" flashvars="strOEM=mt&strSplashImage=./assets/loadinglogo.jpg&strLang=english&strSelectableLangs=english,chinese, portuguese_brazil,german,french,spanish&strIPRSSrvHost=85.118.26.10&strGPSSrvHost=85.118.26.16&strGPSSrvSoapPort=8081&strGPSSrvFwdPort=26000&strLoginMode=simple&strUserSIP=&strUserPswd=&strSOSSrvHost=85.118.26.17&strSOSSrvSoapPort=8082&strSOSSrvFwdPort=26001&strClientServicePort=&strSOSLoginMode=simple&themeColor=a7c3e3&showRTTPriority=false&showGPSUpdateRate=true&nSamePosErrMeters=300&nDelayForMapReadySecs=10&nGPSUpdatesRateSecs=65535&nGPSSubscriptionsIntervalMinutes=10&nLat=48.311058&nLng=11.636753&nZoomLevel=13.0&strClientServiceVersion=2.1.36.04&bDispatcherEndsSessions=true&nSOSSubscriptionsIntervalMinutes=1&GPSKATime=20&SOSKATime=20&nPathDotsSize=2&nPathWidth=5&bHideAnnounce=false&bHideEmergencyPan=false&bHideDebugLog=false&showMutedColumn=false&strLogFilter=&strMapMarkerLabelMode=name&key=ABQIAAAAfJEcVYS6-jYp2UOUy8Wh5xSCeXAFBxztfWxjY5w1WzTnKjnSVRS7Uu5XoOIwTg2R_tq_c0QSCPxSHw" type="application/x-shockwave-flash">
]
答案 0 :(得分:2)
你能跑吗:
function sendToActionscript(str)
{
var swf = jQuery("#IPRS_Dispatcher", parent.document);
console.log('step1');
console.log(swf);
console.log('step2');
console.log.(swf.html());
console.log('step3');
swf.LogAddItem(30, str);
console.log('step4');
}
好的,下一个调试步骤:运行:
function sendToActionscript(str)
{
var swf = parent.top.$(“#IPRS_Dispatcher”);
console.log('step1');
console.log($);
console.log('step2');
console.log.(jQuery);
console.log('step3');
console.log(parent.document);
console.log('step4');
}
修改
步骤输出
step1
function (j,s){return new b.fn.init(j,s)} iframecontent.html:49
step2
[
<embed src="DispatcherMain.swf" width="100%" height="100%" align="middle" id="IPRS_Dispatcher" quality="high" name="IPRS_Dispatcher" wmode="opaque" allowfullscreen="true" allowscriptaccess="sameDomain" pluginspage="http://www.adobe.com/go/getflashplayer" flashvars="strOEM=mt&strSplashImage=./assets/loadinglogo.jpg&strLang=english&strSelectableLangs=english,chinese, portuguese_brazil,german,french,spanish&strIPRSSrvHost=85.118.26.10&strGPSSrvHost=85.118.26.16&strGPSSrvSoapPort=8081&strGPSSrvFwdPort=26000&strLoginMode=simple&strUserSIP=&strUserPswd=&strSOSSrvHost=85.118.26.17&strSOSSrvSoapPort=8082&strSOSSrvFwdPort=26001&strClientServicePort=&strSOSLoginMode=simple&themeColor=a7c3e3&showRTTPriority=false&showGPSUpdateRate=true&nSamePosErrMeters=300&nDelayForMapReadySecs=10&nGPSUpdatesRateSecs=65535&nGPSSubscriptionsIntervalMinutes=10&nLat=48.311058&nLng=11.636753&nZoomLevel=13.0&strClientServiceVersion=2.1.36.04&bDispatcherEndsSessions=true&nSOSSubscriptionsIntervalMinutes=1&GPSKATime=20&SOSKATime=20&nPathDotsSize=2&nPathWidth=5&bHideAnnounce=false&bHideEmergencyPan=false&bHideDebugLog=false&showMutedColumn=false&strLogFilter=&strMapMarkerLabelMode=name&key=ABQIAAAAfJEcVYS6-jYp2UOUy8Wh5xSCeXAFBxztfWxjY5w1WzTnKjnSVRS7Uu5XoOIwTg2R_tq_c0QSCPxSHw" type="application/x-shockwave-flash">
]
step3 iframecontent.html:52
#document
step4
好的,现在只需尝试
function sendToActionscript(str)
{
var swf = parent.top.$(“#IPRS_Dispatcher”);
swf.LogAddItem(30, str);
}
您的Flex应用中存在错误
最终解决了
// get flash movie object
var flashMovie;
function init() {
if (document.getElementById) {
flashMovie = parent.document.getElementById("IPRS_Dispatcher");
}
}
// wait for the page to fully load before initializing
window.onload = init;
function callToFlash(str)
{
var bool = flashMovie.sendToFlash(str);
}
我认为在初始化之前等待页面完全加载是修复。
您也可以使用http://api.jquery.com/ready/
$(document).ready(init);
在DOM初始化后使其工作。