国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發 > Flex > 正文

在Flex(Flash)中嵌入HTML代碼或頁面(Flex IFrame)

2024-09-08 18:17:19
字體:
來源:轉載
供稿:網友

在flex組件中嵌入html代碼,可以利用flex iframe。這個在很多時候會用到的,有時候flex必須得這樣做,如果你不這樣做還真不行……

flex而且可以和html進行JavaScript交互操作,flex調用到html中的JavaScript方法以及獲取調用后的返回值。

1、flex iframe下載地址:https://github.com/downloads/flex-users/flex-iframe/flex-iframe-1.5.1.zip

下載完成后目錄如下
 
asdoc就是文檔doc了
bin有需要用到的flex庫 swc
examples就是示例
sources源代碼

2、將bin目錄中的swc引入到你的flex工程中,并加入代碼片段如下

復制代碼 代碼如下:

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
xmlns:flexiframe="http://code.google.com/p/flex-iframe/"
horizontalAlign="center" verticalAlign="middle" xmlns:s="library://ns.adobe.com/flex/spark">

<mx:Script>
<![CDATA[
import mx.controls.Alert;
protected function sayHelloHandler(event:MouseEvent):void {
// 調用當前iframe嵌入頁面中的sayHello 的JavaScript方法
iFrameBySource.callIFrameFunction("sayHello");
}

protected function sayHandler(event:MouseEvent):void {
// 調用當前iframe嵌入頁面中的say的JavaScript方法,并傳入一個參數
iFrameBySource.callIFrameFunction("say", ["hello world!"]);
}
protected function sayHiHandler(event:MouseEvent):void {
// 調用當前iframe嵌入頁面中的sayHi的JavaScript方法,并傳入2個參數。sayHi方法會返回一個字符串,最后一個回調就是輸出值的函數
iFrameBySource.callIFrameFunction("sayHi", ["hello world", "李四"], function (data:*): void {
Alert.show(data);
});
}
]]>
</mx:Script>

<!-- HTML content stored in a String -->
<mx:String id="iFrameHTMLContent">
<![CDATA[
<html>
<head>
<title>About</title>
</head>
<body>
<div>About</div>
<p>Simple HTML Test application. This test app loads a page of html locally.</p>
<div>Credits</div>
<p> </p>
<p>IFrame.as is based on the work of</p>
<ul>
<li><a target="_top">Christophe Coenraets</a></li>
<li><a target="_top">Brian Deitte</a></li>
</ul>
</body>
</html>
]]>
</mx:String>

<mx:Panel width="80%" height="80%" title="使用source本地遠程頁面">
<flexiframe:IFrame id="iFrameBySource" width="100%" height="100%" source="frame.html"/>
<s:Button label="sayHello" click="sayHelloHandler(event)"/>
<s:Button label="say-param" click="sayHandler(event)"/>
<s:Button label="sayHi" click="sayHiHandler(event)"/>
</mx:Panel>

<mx:Panel width="80%" height="80%" title="使用source加載遠程頁面">
<flexiframe:IFrame id="iFrameByRemoteSource" width="100%" height="100%" source="http://www.baidu.com" visible="true"
overlayDetection="true" />
</mx:Panel>

<mx:Panel width="80%" height="80%" title="使用content屬性 加載本地html文本內容">
<flexiframe:IFrame id="iFrameByContent" width="100%" height="100%" content="{iFrameHTMLContent}"/>
</mx:Panel>

</mx:Application>

frame.html 頁面內容
復制代碼 代碼如下:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>frame.html</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<script type="text/javascript">
// 無參數
function sayHello() {
alert("hello......");
}

// 1個參數
function say(message) {
alert("your say: " + message);
}

// 多個參數 并返回值
function sayHi(message, name) {
alert("your say: " + message + ", name: " + name);
return "your say: " + message + ", name: " + name;
}
</script>

</head>

<body>
flex frame example html page!
<input type="button" value="say" onclick="sayHello()"/>
</body>
</html>

要注意的是:你的flex項目工程需要發表到http的應用服務器(如tomcat、jboss、iis)這些服務器中,用http請求方式才能調用到頁面內容和JavaScript方法。如果不發布到應用服務器中,那樣只能在iframe中嵌套遠程的http請求的頁面,本地靜態頁面是無法顯示的。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 明水县| 遂平县| 鄯善县| 梨树县| 扎兰屯市| 班玛县| 海林市| 历史| 丹东市| 岳阳市| 桐梓县| 永德县| 海原县| 汉川市| 新野县| 恩施市| 繁昌县| 阜新| 安乡县| 泾源县| 松滋市| 马公市| 延津县| 双柏县| 方山县| 神木县| 桐乡市| 华安县| 电白县| 汝州市| 雷波县| 潞西市| 玉山县| 威海市| 临武县| 南京市| 屯留县| 淅川县| 开封县| 正阳县| 瓦房店市|