2012-06-21 45 views
1

我有一個flex應用程序,頂部分層的iframe。Iframe Javascript調用到Flex

我想調用iframe來使用javascript進行flex。

到目前爲止,我已經試過這樣:

這是包含在文檔根

<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); 
功能在SWF嵌入對象

FYI

public function callFromJavaScript(str):void 
    { 
    LogAddItem(30, str); 
    } 

以我IFRAME我已經添加了功能

function callToFlash(str) 
{ 
    var swf = parent.top.$("#IPRS_Dispatcher"); 
    var bool = swf.sendToFlash(str); 
} 

立即得到錯誤在鉻 - 未捕獲的類型錯誤:對象[對象的對象]無方法

UPDATE 25/06/2012「sendToFlash」 - 從輸出的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

你可以把它放在什麼地方嗎?像保管箱或jsfiddle或託管?所以我可以幫助你調試? –

+0

錯誤是Flex錯誤還是JavaScript錯誤? – JeffryHouser

+0

JavaScript錯誤 –

回答

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); 
} 

存在錯誤在您的柔性應用程序 enter image description here

終於解決

// 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初始化後的工作。

+0

未捕獲的SyntaxError:意外的標記(從這裏,我刪除了第2步,錯誤清除。我現在得到 - step1 [] step3 Uncaught TypeError:Object# has no method'LogAddItem' –

+0

看起來像var swf = jQuery(「IPRS_Dispatcher」,parent.document);沒有捕獲我需要的對象:( –

+0

嘗試下一步。你在什麼瀏覽器? –