2012-06-20 49 views
1

我在我的flex应用程序中实现了一个iframe。该iframe包含谷歌地图和各种JavaScript功能,我可以从我的Flex应用程序调用。将数据从iframe传递到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]。或不同的东西?

感谢

文斯

+0

有无你试过吗?它工作吗?如果不是,您收到了什么错误? – JeffryHouser

回答

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

文档[flashObj]将在flashObj不存在的iframe中工作? –

+0

哦,在这种情况下,我认为你应该看看http://stackoverflow.com/questions/935127/how-to-access-parent-iframe-from-javascript你需要访问来自iframe的确切文档你需要。 –

+0

所以看链接,也许parent.document [flashObj] .iAmCalledFromJavascript(“argument1”,2);代替。 –