HTML嵌入SWF兩種方式
- 采用SWFObject.js(依賴swfobject.js)
<script type="text/javascript">
var swfVersionStr = "10.0.0";
var xiSwfUrlStr = "playerProductInstall.swf";
var flashvars = {};
flashvars.firstname = "Nick";
flashvars.lastname = "Danger";
var params = {};
params.quality = "high";
params.bgcolor = "#ffffff";
params.allowscriptaccess = "sameDomain";
var attributes = {};
attributes.id = "TestProject";
attributes.name = "TestProject";
attributes.align = "middle";
//參數(shù)說明:embedSWF("SWF路徑","嵌入的div的id","寬度","高度","SWF的版本號","player產(chǎn)品安裝swf","給SWF的參數(shù)")
swfobject.embedSWF(
"FlashVarTest.swf", "flashContent", "100%", "100%", swfVersionStr,
xiSwfUrlStr, flashvars, params, attributes);
swfobject.createCSS("#flashContent", "display:block;text-align:left;");
</script>
<object id='mySwf' classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' height='100%' width='100%'>
<param name='src' value='FlashVarTest.swf'/>
<param name='flashVars' value='firstname=Nick&lastname=Danger'/>
<embed name='mySwf' src='FlashVarTest.swf' height='100%' width='100%' flashVars='firstname=Nick&lastname=Danger'/>
</object>
<div id="flashContent">
<p>
當(dāng)瀏覽器沒有安裝FlashPlayer的時(shí)候肠槽,顯示此內(nèi)容熙揍。(PS:一般在這里面加上FlashPlayer下載提示和下載地址(可以自定義內(nèi)網(wǎng)地址))
</p>
<p>
To view this page ensure that Adobe Flash Player version
${version_major}.${version_minor}.${version_revision} or greater is installed.
</p>
<script type="text/javascript">
var pageHost = ((document.location.protocol == "https:") ? "https://" : "http://");
document.write("<a ><img src='"
+ pageHost + "www.adobe.com/images/shared/download_buttons/get_flash_player.gif' alt='Get Adobe Flash player' /></a>" );
</script>
</div>
HTML 往SWF中傳參數(shù)
var flashvars = {};
flashvars.firstname = "Nick";
flashvars.lastname = "Danger";
swfobject.embedSWF(
"FlashVarTest.swf", "flashContent", "100%", "100%", "",
"", flashvars,{},{});
<object id='mySwf' classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' height='100%' width='100%'>
<param name='src' value='FlashVarTest.swf'/>
<!-- 傳參數(shù)蛔翅,必須滿足URL編碼格式 -->
<param name='flashVars' value='firstname=Nick&lastname=Danger'/>
<embed name='mySwf' src='FlashVarTest.swf' height='100%' width='100%' flashVars='firstname=Nick&lastname=Danger'/>
</object>
//swfobject
swfobject.embedSWF(
"FlashVarTest.swf?firstname=Nick&lastname=Danger",
"flashContent", "100%", "100%",
swfVersionStr, xiSwfUrlStr,
flashvars, params, attributes);
//<object>
<object id='mySwf' classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' height='100%' width='100%'>
<param name='src' value='FlashVarTest.swf?firstname=Nick&lastname=Danger'/>
</object>
- 服務(wù)器頁面動(dòng)態(tài)傳參
- JSP
<%
String fName = (String) request.getParameter("firstname");
String lName = (String) request.getParameter("lastname");
%>
<script type="text/javascript">
var swfVersionStr = "0";
var xiSwfUrlStr = "";
var flashvars = {};
flashvars.firstname = "<%= fName %>";
flashvars.lastname = "<%= lName %>";
var params = {};
params.quality = "high";
params.bgcolor = "#ffffff";
params.allowscriptaccess = "sameDomain";
var attributes = {};
attributes.id = "FlashVarTest";
attributes.name = "FlashVarTest";
attributes.align = "middle";
swfobject.embedSWF(
"FlashVarTest.swf", "flashContent",
"100%", "100%",
swfVersionStr, xiSwfUrlStr,
flashvars, params, attributes);
</script>
<?php
@ $fName = $_GET['firstname'];
@ $lName = $_GET['lastname'];
?>
<script type="text/javascript">
var swfVersionStr = "";
var xiSwfUrlStr = "";
var flashvars = {};
flashvars.firstname = "<?php echo $fName; ?>"
flashvars.lastname = "<?php echo $lName; ?>"
var params = {};
params.quality = "high";
params.bgcolor = "#ffffff";
params.allowscriptaccess = "sameDomain";
var attributes = {};
attributes.id = "FlashVarTest";
attributes.name = "FlashVarTest";
attributes.align = "middle";
swfobject.embedSWF(
"FlashVarTest.swf", "flashContent",
"100%", "100%",
swfVersionStr, xiSwfUrlStr,
flashvars, params, attributes);
swfobject.createCSS("#flashContent", "display:block;text-align:left;");
</script>
SWF 中獲取參數(shù)
- 獲取指定參數(shù)值
FlexGlobals.topLevelApplication.parameters.firstname
- 通過
for .. in
遍歷所有的屬性名稱和屬性值
for (var att:String in FlexGlobals.topLevelApplication.parameters) {
trace( att + ":" + FlexGlobals.topLevelApplication.parameters[att] );
}
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600">
<fx:Script>
<![CDATA[
import mx.core.FlexGlobals;
protected function button2_clickHandler(event:MouseEvent):void
{
log.text += "firstName:"+FlexGlobals.topLevelApplication.parameters.firstName +"\n";
}
protected function button3_clickHandler(event:MouseEvent):void
{
log.text += "=============開始遍歷flashvar對象========\n";
for (var i:String in FlexGlobals.topLevelApplication.parameters) {
log.text += i + ":" + FlexGlobals.topLevelApplication.parameters[i] + "\n";
}
log.text += "=============結(jié)束遍歷flashvar對象========\n";
}
]]>
</fx:Script>
<fx:Declarations>
<!-- 將非可視元素(例如服務(wù)、值對象)放在此處 -->
</fx:Declarations>
<s:VGroup width="100%">
<s:HGroup width="100%">
<s:Button label="獲取firstName參數(shù)值" click="button2_clickHandler(event)"/>
<s:Button label="遍歷參數(shù)中所有的屬性名稱和屬性值" click="button3_clickHandler(event)"/>
</s:HGroup>
<s:Label text="輸出日志:"/>
<s:TextArea id="log" width="100%" />
</s:VGroup>
</s:Application>