这段时间一直在苦心研究Flex,今天突然想,我们平时都是把swf放到网页中,怎么才能把网页嵌入到Flex中呢?我查了一些资料,然后经过自己的不懈努力,终于搞定。 
为了方便,写了个嵌入HTML页面的代理IFrame组件,该组件封装了所有需要的Flex端代码,后面只要通过标签调用就OK了。 
IFrame.mxml文件如下:

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml" resize="callLater(moveIFrame)" move="callLater(moveIFrame)" initialize="init();">
  3. <mx:Script>
  4. <![CDATA[
  5. import mx.controls.Alert;
  6. import flash.external.ExternalInterface;
  7. import flash.geom.Point;
  8. import flash.net.navigateToURL;
  9. private var __source: String;
  10. //Flash场景0,0坐标 var localPt:Point = new Point(0, 0);
  11. //转换为浏览器页面坐标 var globalPt:Point = this.localToGlobal(localPt);
  12. //这样就可以在Flex页面中嵌入任意的HTML页面了,为了方便,
  13. public function moveIFrame():void
  14. {
  15. var localPoint:Point = new Point(0, 0);
  16. var globalPoint:Point = this.localToGlobal(localPoint);
  17. ExternalInterface.call("moveIFrame", globalPoint.x, globalPoint.y, this.width, this.height);
  18. }
  19. //调用javaScript的loadIFrame方法,设置IFrame的src(URL)
  20. public function set source(source: String): void {
  21. if (source)
  22. {
  23. if (!ExternalInterface.available)
  24. {
  25. Alert.show("The ExternalInterface is not available in this container. Internet Explorer ActiveX, " +
  26. "Firefox, Mozilla 1.7.5 and greater, or other browsers that support NPRuntime are required.");
  27. }
  28. __source = source;
  29. //Alert.show(source);
  30. ExternalInterface.call("loadIFrame",source);
  31. }
  32. }
  33. //初始化时注册供javaScript调用的方法
  34. public function init():void
  35. {
  36. ExternalInterface.addCallback("IFrameOnBulr",showIFrameAgain);
  37. }
  38. //javaScript调用IFrameOnBlur方法时的处理方法
  39. public function showIFrameAgain():void
  40. {
  41. this.source=this.__source;
  42. this.showIFrame=true;
  43. this.moveIFrame();
  44. }
  45. //调用javaScript的IFrameShow方法,设置IFrame的可见状态
  46. public function set showIFrame(display:Boolean):void
  47. {
  48. ExternalInterface.call("IFrameShow",display);
  49. }
  50. public function get source(): String {
  51. return __source;
  52. }
  53. //重载了Canvas的visible属性,以便在Canvas隐藏HTML页面中的IFrame
  54. override public function set visible(visible: Boolean): void
  55. {
  56. super.visible=visible;
  57. if (visible)
  58. {
  59. ExternalInterface.call("showIFrame");
  60. }
  61. else
  62. {
  63. ExternalInterface.call("hideIFrame");
  64. }
  65. }
  66. ]]>
  67. </mx:Script>
  68. </mx:Canvas>
  69. IFremaDemo.mxml文件如下
    • <?xml version="1.0" encoding="utf-8"?>
    • <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" xmlns:zq="*">
    • <zq:IFrame mouseUp="Iframe.showIFrame=true;Iframe.moveIFrame();Iframe.source=Iframe.source" id="Iframe" source="http://weather.news.qq.com/inc/ss258.htm" x="240" y="23"  width="190" height="190"/>
    • </mx:Application>

    当然少不了js代码,IFremaDemo.html网页是Flex Builder3自动生成的,然后需要加上以下代码:

    1. <script>
    2. function moveIFrame(x,y,w,h) {
    3. var frameRef=document.getElementById("myFrame");
    4. frameRef.style.left=x;
    5. frameRef.style.top=y;
    6. }
    7. function loadIFrame(url){
    8. document.getElementById("myFrame").src=url;
    9. }
    10. function IFrameShow(display){
    11. document.getElementById("myFrame").style.visibility=display?"visible":"hidden";
    12. }
    13. function IFrameOnBulr()
    14. {
    15. //根据id获取flash实例,ListDemo,可以从Embed
    16. var flash = (navigator.appName.indexOf ("Microsoft") !=-1)?window["IFremaDemo"]:document["IFremaDemo"];
    17. //调用ActionScript注册的回调方法
    18. flash.IFrameOnBulr();
    19. }
    20. </script>
    21. <iframe id="myFrame" name="myFrame" onblur="this.style.visibility='visible';IFrameOnBulr();" width="189" height="190" marginwidth="0" marginheight="0" hspace="0" vspace="0" frameborder="0" scrolling="no" style="position:absolute;"></iframe>

转自:http://www.cnblogs.com/YNLDY/archive/2012/02/07/2340968.html

Flex嵌入HTML页面的更多相关文章

  1. [Flex] IFrame系列 —— 嵌入本地页面两种方式source和content(html页面和html代码)

    <?xml version="1.0" encoding="utf-8"?> <s:Application xmlns:fx="ht ...

  2. WebIM(5)----将WebIM嵌入到页面中

    在之前的文章中,已经开发了一个简单的WebIM,但是这个WebIM是在独立的页面中的,今天发布的WebIM是一个可以嵌入到自己网页中的版本,你只需添加少量的代码,就可以在页面中嵌入一个WebIM.不过 ...

  3. iPhone的App嵌入html页面问题

    测试环境:iPhone ios 11.0.3 问题:iPhone App嵌入HTML页面,页面拉动到底部时,手势从屏幕底部边缘开始往上拉动,页面出现白色图层,且html页面一屏外的会卡住,无法滚动,需 ...

  4. react native (2) 嵌入h5页面 设置顶部导航

    嵌入h5页面 1.新建好页面 2. import { WebView } from 'react-native'; 3.<WebView source={{ uri: '要引入的页面路径' }} ...

  5. vue在页面嵌入别的页面或者是视频2

    vue在页面嵌入别的页面或者是视频 以下是嵌入页面 <iframe name="myiframe" id="myrame" src="http: ...

  6. Saiku通过iframe嵌入web页面(六)

    Saiku通过iframe嵌入系统页面 前提: Saiku已安装好,并且配置了数据源,熟练了saiku的基本使用. 一.将整个Saiku嵌入页面 在web项目中,新建index.jsp页面,内容如下: ...

  7. SVG系列教程:SVG简介与嵌入HTML页面的方式

    地址:http://www.w3cplus.com/html5/svg-introduction-and-embedded-html-page.html 随着技术向前的推进,SVG相关的讨论也越渐频繁 ...

  8. SSI注入--嵌入HTML页面中的指令,类似jsp、asp对现有HTML页面增加动态生成内容,见后面例子

    SSI注入漏洞总结 from:https://www.mi1k7ea.com/2019/09/28/SSI%E6%B3%A8%E5%85%A5%E6%BC%8F%E6%B4%9E%E6%80%BB%E ...

  9. 安卓 apk 嵌入H5页面只显示部分

    安卓 apk 嵌入H5页面只显示部分(有空白页出现) 解决方案 没有加载的是js部分,需要在安卓那边加上一串代码 webView.getSetting().setDomStorageEnabled(t ...

随机推荐

  1. Scala 学习记录(一)

    1. 相对于java,scala的值修饰用val,变量修饰用var.值相当于java的final 修饰了. package demo object ScalaBase extends App { pr ...

  2. monkeyrunner 简单用例编写

    monkeyrunnerfrom com.android.monkeyrunner import MonkeyRunner,MonkeyDevice,MonkeyImagedevice = Monke ...

  3. elasticsearch时间格式DateFormat的含义

    时间格式 枚举(或者英文)format pattern 含义 custom - 自定义属性 none - 不转化 basic_date yyyyMMdd 基本时间 basic_date_time   ...

  4. Qt _六天的学习路线

    六天的学习路线:第一天:    1.Qt的介绍    2.Qt的框架    3.项目文件(.pro)    4.第一个Qt程序(hello Qt)    5.父窗口和子窗口的区别(控件,部件,构件)  ...

  5. 字符串 || CodeForces 591B Rebranding

    给一字符串,每次操作把字符串中的两种字母交换,问最后交换完的字符串是多少 arr数组记录每个字母最后被替换成了哪个字母 读入字符前面加一空格 scanf(" %c %c", &am ...

  6. linux 查看分区UUID的两种方法

    1. sudo blkid /dev/loop0: TYPE="squashfs"/dev/loop1: TYPE="squashfs"/dev/loop2: ...

  7. process data

    # version 1.0def connect_mysql(sql, oper_type="select", data_l=None): conn = pymysql.conne ...

  8. bzoj2588 counting on a tree

    题目不难,树上可持久化数据结构. 帖代码: #include<cstdio> #include<algorithm> using namespace std; #define ...

  9. qemu-img————QEMU的磁盘管理工具

    qemu-img command [command options] Command: check [-f fmt] filename                       # 对磁盘镜像文件进 ...

  10. day17-python之文件操作

    1.内置函数 #!/usr/bin/env python # -*- coding:utf-8 -*- # print(abs(-1)) # print(abs(1)) # # print(all([ ...