Flex嵌入HTML页面
这段时间一直在苦心研究Flex,今天突然想,我们平时都是把swf放到网页中,怎么才能把网页嵌入到Flex中呢?我查了一些资料,然后经过自己的不懈努力,终于搞定。
为了方便,写了个嵌入HTML页面的代理IFrame组件,该组件封装了所有需要的Flex端代码,后面只要通过标签调用就OK了。
IFrame.mxml文件如下:
- <?xml version="1.0" encoding="utf-8"?>
- <mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml" resize="callLater(moveIFrame)" move="callLater(moveIFrame)" initialize="init();">
- <mx:Script>
- <![CDATA[
- import mx.controls.Alert;
- import flash.external.ExternalInterface;
- import flash.geom.Point;
- import flash.net.navigateToURL;
- private var __source: String;
- //Flash场景0,0坐标 var localPt:Point = new Point(0, 0);
- //转换为浏览器页面坐标 var globalPt:Point = this.localToGlobal(localPt);
- //这样就可以在Flex页面中嵌入任意的HTML页面了,为了方便,
- public function moveIFrame():void
- {
- var localPoint:Point = new Point(0, 0);
- var globalPoint:Point = this.localToGlobal(localPoint);
- ExternalInterface.call("moveIFrame", globalPoint.x, globalPoint.y, this.width, this.height);
- }
- //调用javaScript的loadIFrame方法,设置IFrame的src(URL)
- public function set source(source: String): void {
- if (source)
- {
- if (!ExternalInterface.available)
- {
- Alert.show("The ExternalInterface is not available in this container. Internet Explorer ActiveX, " +
- "Firefox, Mozilla 1.7.5 and greater, or other browsers that support NPRuntime are required.");
- }
- __source = source;
- //Alert.show(source);
- ExternalInterface.call("loadIFrame",source);
- }
- }
- //初始化时注册供javaScript调用的方法
- public function init():void
- {
- ExternalInterface.addCallback("IFrameOnBulr",showIFrameAgain);
- }
- //javaScript调用IFrameOnBlur方法时的处理方法
- public function showIFrameAgain():void
- {
- this.source=this.__source;
- this.showIFrame=true;
- this.moveIFrame();
- }
- //调用javaScript的IFrameShow方法,设置IFrame的可见状态
- public function set showIFrame(display:Boolean):void
- {
- ExternalInterface.call("IFrameShow",display);
- }
- public function get source(): String {
- return __source;
- }
- //重载了Canvas的visible属性,以便在Canvas隐藏HTML页面中的IFrame
- override public function set visible(visible: Boolean): void
- {
- super.visible=visible;
- if (visible)
- {
- ExternalInterface.call("showIFrame");
- }
- else
- {
- ExternalInterface.call("hideIFrame");
- }
- }
- ]]>
- </mx:Script>
- </mx:Canvas>
- 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自动生成的,然后需要加上以下代码:
- <script>
- function moveIFrame(x,y,w,h) {
- var frameRef=document.getElementById("myFrame");
- frameRef.style.left=x;
- frameRef.style.top=y;
- }
- function loadIFrame(url){
- document.getElementById("myFrame").src=url;
- }
- function IFrameShow(display){
- document.getElementById("myFrame").style.visibility=display?"visible":"hidden";
- }
- function IFrameOnBulr()
- {
- //根据id获取flash实例,ListDemo,可以从Embed
- var flash = (navigator.appName.indexOf ("Microsoft") !=-1)?window["IFremaDemo"]:document["IFremaDemo"];
- //调用ActionScript注册的回调方法
- flash.IFrameOnBulr();
- }
- </script>
- <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页面的更多相关文章
- [Flex] IFrame系列 —— 嵌入本地页面两种方式source和content(html页面和html代码)
<?xml version="1.0" encoding="utf-8"?> <s:Application xmlns:fx="ht ...
- WebIM(5)----将WebIM嵌入到页面中
在之前的文章中,已经开发了一个简单的WebIM,但是这个WebIM是在独立的页面中的,今天发布的WebIM是一个可以嵌入到自己网页中的版本,你只需添加少量的代码,就可以在页面中嵌入一个WebIM.不过 ...
- iPhone的App嵌入html页面问题
测试环境:iPhone ios 11.0.3 问题:iPhone App嵌入HTML页面,页面拉动到底部时,手势从屏幕底部边缘开始往上拉动,页面出现白色图层,且html页面一屏外的会卡住,无法滚动,需 ...
- react native (2) 嵌入h5页面 设置顶部导航
嵌入h5页面 1.新建好页面 2. import { WebView } from 'react-native'; 3.<WebView source={{ uri: '要引入的页面路径' }} ...
- vue在页面嵌入别的页面或者是视频2
vue在页面嵌入别的页面或者是视频 以下是嵌入页面 <iframe name="myiframe" id="myrame" src="http: ...
- Saiku通过iframe嵌入web页面(六)
Saiku通过iframe嵌入系统页面 前提: Saiku已安装好,并且配置了数据源,熟练了saiku的基本使用. 一.将整个Saiku嵌入页面 在web项目中,新建index.jsp页面,内容如下: ...
- SVG系列教程:SVG简介与嵌入HTML页面的方式
地址:http://www.w3cplus.com/html5/svg-introduction-and-embedded-html-page.html 随着技术向前的推进,SVG相关的讨论也越渐频繁 ...
- 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 ...
- 安卓 apk 嵌入H5页面只显示部分
安卓 apk 嵌入H5页面只显示部分(有空白页出现) 解决方案 没有加载的是js部分,需要在安卓那边加上一串代码 webView.getSetting().setDomStorageEnabled(t ...
随机推荐
- Google的Java编程风格指南
作者:Hawstein出处:http://hawstein.com/posts/google-java-style.html声明:本文采用以下协议进行授权: 自由转载-非商用-非衍生-保持署名|Cre ...
- php 缓存工具类 实现网页缓存
php 缓存工具类 实现网页缓存 php程序在抵抗大流量访问的时候动态网站往往都是难以招架,所以要引入缓存机制,一般情况下有两种类型缓存 一.文件缓存 二.数据查询结果缓存,使用内存来实现高速缓存 本 ...
- 不能说的hidden
不能说的hidden 时光跑跑...路在脚下...晨光依在...----Vashon 1.所谓"时尚",本质上就是自己看不见自己的样子.好比我们在地球上,却感觉不到地球在动. 2. ...
- 【HEVC帧间预测论文】P1.9 Coding Tree Depth Estimation for Complexity Reduction of HEVC
Coding Tree Depth Estimation for Complexity Reduction of HEVC <HEVC标准介绍.HEVC帧间预测论文笔记>系列博客,目录见: ...
- HYSBZ 1086 王室联邦 (树的分块)
题意:国王想把他的国家划分成若干个省.他的国家有n个城市,是一棵树,即n-1条边,编号为1..n.为了防止管理太过分散,每个省至少要有B个城市,为了能有效的管理,每个省最多只有3B个城市.每个省必须有 ...
- HYSBZ 1588 营业额统计 (Splay树)
题意:给出一个公司每一天的营业额,求每天的最小波动值之和.该天的最小波动值= min { 绝对值| 该天以前某一天的营业额-该天的营业额 | }.第一天的最小波动值就是其自己. 思路:Splay伸展树 ...
- Python 基础语法学习(第一讲)---类的使用
[写在前面]:其实自学python有一段时间了,但是一直没想起来要写博客来记录自己的学习,今天才感觉要写点什么让自己学的更扎实一点,所以从今天开始更新python自学系列,希望看见文章的大佬们可以指点 ...
- Django 你需要了解的入门操作
创建一个django project (我的版本是1.11.11) django-admin startproject mysite cd mysite 当前目录下会生成mysite的工程,目录结 ...
- uva1442 Cav
连通器向左向右扫描两次即可每一段有水的连通区域,高度必须相同,且不超过最低天花板高度if(p[i] > level) level = p[i]; 被隔断,要上升(隔断后,之前的就不变了,之后的从 ...
- linux下的基础操作
Xfce 终端: Linux 命令行终端,打开后会进入 zsh Shell 环境,可以使用 Linux 命令. NetSurf 网络浏览器:浏览器,可以用在需要前端界面的课程里,只需要打开环境里写的 ...