1

I have implemented an iframe into my flex application. The iframe contains a google map and various JavaScript functions which i am successfully able to call from my flex app.

like so

ExternalInterface.call("top.frames[0].addMarker", i, latitude, longitude, timestamp, user, state, datestring);

But now i want to pass data in the other direction.

I have found the following article http://webdevwonders.com/communication-between-flex-and-javascript/

which shows usage of addcallback

ExternalInterface.addCallback( "iAmCalledFromJavascript", iAmCalledFromJavascript);

do i need to add the same top.frames[0]. or something different?

Thanks

Vince

Vince Lowe
  • 3,521
  • 7
  • 36
  • 63

1 Answers1

1

No you don't need to add top.frames[0]. cause you calling ActionScript inside of Flex from JavaScript, and there are no such thing like DOM frames inside of Flex.

Just keep using the same approach from JavaScript as before: But more details about accessing parent iframe document can be found here http://www.esqsoft.com/javascript_examples/iframe_talks_to_parent/

// This is the function that gets called from ActionScript
function iAmCalledFromAS(argument1, argument2) {

    // Do whatever you like in here
    return "result";
}

function initCommunication() {

    // 'FlexJSExample' is the id of the Flash object
    var flashObj = "FlexJSExample";
    parent.$("iframe").each(function(iel, el) {
      if(el.contentWindow === window)
        // call the previously in ActionScript defined callback function of the Flash object
        el[flashObj].iAmCalledFromJavascript("argument1", 2);
    });
   }
}
Eugene Hauptmann
  • 1,255
  • 12
  • 16
  • document[flashObj] will work from within an iframe where flashObj is not present? – Vince Lowe Jun 20 '12 at 16:18
  • oh, in that case I think you should take a look to http://stackoverflow.com/questions/935127/how-to-access-parent-iframe-from-javascript You need to get access to that exact document from iframe you need. – Eugene Hauptmann Jun 20 '12 at 16:24
  • so looking at link, maybe parent.document[flashObj].iAmCalledFromJavascript("argument1", 2); instead. – Vince Lowe Jun 21 '12 at 08:58
  • updated question with code example - http://stackoverflow.com/questions/11137676/iframe-javascript-call-to-flex – Vince Lowe Jun 21 '12 at 12:15