Flex(Flash)にHTMLコードまたはページを埋め込む(Flex IFrame)


flexコンポーネントにhtmlコードを埋め込み、flex frameを利用することができます。これは多くの時に使われます。flexはこのようにしなければならない場合があります。flexはJavaScriptと相互作用して、flexはこれまでのJavaScriptのメソッドと呼び出し後の戻り値を取得します。1、flex iframeダウンロード住所:https://github.com/downloads/flex-users/flex-iframe/flex-iframe-1.5.1.zip ダウンロード完了後のディレクトリは以下の通りです。 asdocとは、文書docです。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 href="http://coenraets.org/" target="_top">Christophe Coenraets</a></li>
<li><a href="http://www.deitte.com/" 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.ページの内容
 
<!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>
を参照してください。iis)これらのサーバーでは、http要求方式でページの内容とJavaScriptメソッドに呼び出すことができます。アプリケーションサーバに投稿しないと、リモートhttp要求のページをiframeに含めるだけで、ローカル静止ページは表示されません。