flex3 接受外部参数

1、一般状况

 

html:

 

<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" width="550" height="450">
       <param name="allowScriptAccess" value="always">
       <param name="movie" value="test4.swf?color=red&type=pants">
	   <param name="allowFullScreen" value="true"></param>
       <param name="quality" value="high">
       <param name="bgcolor" value="#ffffff">
	   <PARAM name="wmode" value="transparent">
       <embed src="test4.swf?color=red&type=pants" quality="high" wmode="transparent" bgcolor="#ffffff" width="550" height="400" allowScriptAccess="always" allowfullscreen="true" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />
</object>

 

或者用flashvars参数传值

 

<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" width="550" height="450">
       <param name="allowScriptAccess" value="always">
       <param name="movie" value="test4.swf">
	   <param name="allowFullScreen" value="true"></param>
       <param name="quality" value="high">
       <param name="bgcolor" value="#ffffff">
	   <PARAM name="wmode" value="transparent">
	   <param name="FlashVars" value="color=red&type=pants" />
       <embed src="test4.swf" quality="high" flashVars="color=red&type=pants" wmode="transparent" bgcolor="#ffffff" width="550" height="400" allowScriptAccess="always" allowfullscreen="true" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />
</object>
 

 

flex: (即:text4.swf 的代码)

 

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="horizontal" applicationComplete="initApp()">
	<mx:Script>
		<![CDATA[
			[Bindable] public var color:String;			
			[Bindable] public var type:String;
			
			private function initApp():void{
				color = Application.application.parameters.color;
				type = Application.application.parameters.type;
				txtArea.text='Color: ' + color + ' ; Type: ' + type;
			}
		]]>
	</mx:Script>
	
	<mx:TextArea id="txtArea"/>
</mx:Application>

 

或者用grid显示

 

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical" verticalAlign="middle" backgroundColor="white" creationComplete="init()">
	<mx:Script>
		<![CDATA[
			private function init():void {				
				// The FlashVars
				var obj:Object = Application.application.parameters;
				var item:String;
				
				arrColl = new ArrayCollection();
				/* Populate the ArrayCollection object with the FlashVars. */
				for (item in obj) {
					arrColl.addItem({key:item, value:obj[item]});
				}
				dataGrid.dataProvider = arrColl;
			}
		 ]]>
	</mx:Script>
	<mx:ArrayCollection id="arrColl" />
	<mx:DataGrid id="dataGrid" />
</mx:Application>

 

2、 通过 SWFObject

 

目前SWFObject最新版为2.0,关于SWFObject的一些资源见下面:


官方站点
http://blog.deconcept.com/swfobject/

 

在google code的地址,这里有SWFObject 2.0的JS包及相关自动代码生成器的下载
http://code.google.com/p/swfobject/

 

SWFObject 2.0 官方文档(英文)
http://code.google.com/p/swfobject/wiki/SWFObject_2_0_documentation

 

SWFObject 2.0 官方文档(中文翻译)
http://farthinker.cn/2007/12/27/swfobject-2_0-doc-translation/

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
	<head>
		<title></title>
		<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
		<script type="text/javascript" src="swfobject.js"></script>
		<script type="text/javascript">
			var flashvars = {
					playname: "test4.swf",
					videoname: "my player",
					wear: "clothes"
				};
			var params = {
					wmode: "transparent",
					bgcolor: "#ffffff",
					allowFullScreen: "true",
					allowScriptAccess: "always",
					quality: "high"
				};
			var attributes = {};
			attributes.id = "flashContent";
			swfobject.embedSWF("test4.swf", "flashContent", "800", "600", "9.0.0", "expressInstall.swf", flashvars, params, attributes);
		</script>
	</head>
	<body>
		<div id="flashContent">
			<a href="http://www.adobe.com/go/getflashplayer">
				<img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" />
			</a>
		</div>
	</body>
</html>
 

flex代码如上一例

 

想要说的是,Google 的YouTube播放器 也用了swfobject

http://code.google.com/apis/ajax/playground/#change_the_playing_video

 

 

 

更多请看flex 与 JavaScript的数据交互



 

 

 

你可能感兴趣的:(JavaScript,Flex,Google,Flash,Adobe)