Flex通过IFrame调用JS函数

为尊重原作者,所以采取链接的方式讲述

首先是下载一个flex-iframe-1.5.1.swc

另外需要下载一个Flex IFrame中文注释使用方法详解 将工程中html-template文件夹中AC_OETags.js index.template.html覆盖,否则不会成功,这步是非常重要的,我做的时候就是没有覆盖此处,利用callIFramFuntion调用js函数始终没有反应,且调试运行时IE未弹出“为帮助保护你的安全,Internet Explorer已经限制此文件显示可能访问你的计算机的活动内容.....”,如果弹出说明你成功了。

然后就是代码了,下面我只讲述简单的代码,并为根据原文编写,若要了解更多,转载原文为:

http://hi.baidu.com/qq825129090/blog/item/b2216085a98c442266096ec0.html(Flex IFrame使用详解[一] 加入IFrme到项目

http://hi.baidu.com/qq825129090/blog/item/b2aa6a48404f4fec83025c01.html(Flex IFrame使用详解[二] 例子:调用IFrme页面的js函数

代码:

test.mxml中

import mx.controls.Alert;
import mx.events.FlexEvent;

protected function bt_clickHandler(event:MouseEvent):void
{
iFrame.callIFrameFunction("showAlert");
}
]]>
</fx:Script>
<flexiframe:IFrame id="iFrame" borderColor="0xFF0000" borderStyle="solid"
  label="ckeditor"
  source="mytest.html"
  width="532"
  height="447"
  overlayDetection="true"  x="250" y="10" contentBackgroundColor="#BBB1B1"/>
<s:Button id="bt" label="调用内联函数" click="bt_clickHandler(event)"/>


mytest.html中

<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
<script type="text/javascript">
function showAlert()
{
alert("1");
}
</script>
</head>
<body>
</body>

你可能感兴趣的:(iframe,function,Flex,button,internet,BT)