1

I have a flex application with an iframe layered on top.

I want to make a call from the iframe to flex with javascript.

So far i have tried this:

This is the Object containing the swf embed in the ROOT document

    <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>

I have added addcallback for the function i want to expose

ExternalInterface.addCallback("sendToFlash", callFromJavaScript);

FYI

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

In my IFRAME i have added the function

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

Now getting error in chrome - Uncaught TypeError: Object [object Object] has no method 'sendToFlash'

UPDATE 25/06/2012 - output from 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">​
] 
3
  • can you put it somewhere? like dropbox or jsfiddle or hosting? so I can help you with debugging? Commented Jun 21, 2012 at 12:16
  • IS that error a Flex error or a JavaScript error? Commented Jun 21, 2012 at 12:17
  • @www.eugenehp.tk sorry i can not Commented Jun 21, 2012 at 12:22

1 Answer 1

2

Can you run please:

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

Okay, next debug step: run this:

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

EDIT

STEPS OUTPUT

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 

okay,so now simply try

function sendToActionscript(str) 
{
  var swf = parent.top.$(“#IPRS_Dispatcher”);
  swf.LogAddItem(30, str);
}

there is an error in your flex app enter image description here

Finally Resolved

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

I think waiting for the page to fully load before initializing was the fix.

You can also use http://api.jquery.com/ready/

$(document).ready(init);

to get it working after DOM initialisation.

Sign up to request clarification or add additional context in comments.

21 Comments

Uncaught SyntaxError: Unexpected token ( from this, i removed step 2 and the error clears. i now get - step1 [] step3 Uncaught TypeError: Object #<Object> has no method 'LogAddItem'
looks like var swf = jQuery("IPRS_Dispatcher", parent.document); isnt capturing the object i need :(
try next step. What browser you're in?
take a look here dushyantpatel.wordpress.com/2009/07/20/… you need to load query into each frame
captures nothing - to see full source of the swf page view the source of this usa-dispatcher.mobiletornado.com/test/IPRS_Dispatcher.html
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.