将数据从iframe传递到flex

时间:2012-06-20 16:00:35

标签: actionscript-3 flash flex iframe

我已经在我的flex应用程序中实现了iframe。 iframe包含一个谷歌地图和各种JavaScript功能,我可以通过我的Flex应用程序成功调用它。

喜欢这样

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

但现在我想向另一个方向传递数据。

我找到了以下文章http://webdevwonders.com/communication-between-flex-and-javascript/

显示了addcallback

的用法
ExternalInterface.addCallback( "iAmCalledFromJavascript", iAmCalledFromJavascript);

我需要添加相同的top.frames [0]。还是别的什么?

由于

文斯

1 个答案:

答案 0 :(得分:1)

不,您不需要添加 top.frames [0]。,因为您从JavaScript中调用Flex内部的ActionScript,而Flex内部没有像DOM这样的东西。

继续使用与以前相同的JavaScript方法: 但是可以在此处找到有关访问父iframe文档的更多详细信息 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);
    });
   }
}