1
votes

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

1
Have have you tried? Is it working? If not, what errors are you receiving?JeffryHouser

1 Answers

1
votes

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