Flex4 中将网页的参数传递给Flash,并且在Flash中读取这些参数

使用Flash Builder 4创建Flex应用,会自动生成网页调用Flash,会有两种方式显示Flash,下面针对这两个方式看看如何添加参数。

方式一(swfobject):

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
         <script type= "text/javascript" >
             <!-- For version detection, set  to min. required Flash Player version,or 0  (or 0.0 . 0 ),255)!important; background:none!important">for  no version detection. -->
             var  swfVersionStr = "10.0.0" ;
<!-- To use  express install,monospace!important; min-height:inherit!important; background:none!important">to playerProductInstall.swf,otherwise the empty string. -->
xiSwfUrlStr = "playerProductInstall.swf" ;
<span style= "color: #000000;" > flash var s = { 1: "abc" , 2: "def" };
</span>            params = {};
params.quality = "high" ;
params.bgcolor = "#ffffff" ;
params.allowscriptaccess = "sameDomain" ;
params.allowfullscreen = "true" ;
attributes = {};
attributes.id = "test39" ;
attributes.name = ;
attributes.align = "middle" ;
swfobject.embedSWF(
                 "test39.swf" ottom:auto!important; float:none!important; height:auto!important; left:auto!important; line-height:1.8em!important; margin:0px!important; outline:rgb(0, "flashContent" ottom:auto!important; float:none!important; height:auto!important; left:auto!important; line-height:1.8em!important; margin:0px!important; outline:rgb(0,
"100%" ottom:auto!important; float:none!important; height:auto!important; left:auto!important; line-height:1.8em!important; margin:0px!important; outline:rgb(0,
                 swfVersionStr,xiSwfUrlStr,
s,params,attributes);
<!-- JavaScript enabled so display the flashContent div in  case  it is  not replaced with  a swf object. -->
swfobject.createCSS( "#flashContent" "display:block;text-align:left;" );
</script>

方式二(html):

23
24
25
26
27
28
<object classid= "clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"  width= "100%"  height= id= <param name= "movie"  value= "demo1.swf"  />
"quality"  "high"  />
"bgcolor"  "#ffffff"  />
"allowScriptAccess"  "sameDomain"  />
"allowFullScreen"  "true"  />
><param name= "flashvars"  "var1=aabb&var2=ccdd"  />
</span>                <!--[ if  !IE]>-->
<object type= "application/x-shockwave-flash"  data= >
                     />
/>
/>
/>
/>
<!--<![endif]-->
<!--[ gte IE 6 ]>-->
<p>
                         Either scripts and active content are not permitted to run or Adobe Flash Player version
                         10.0 or greater not installed.
</p>
<!--<![endif]-->
</a>
!IE]>-->
</object>
<!--<![endif]-->
</object>

 

在Flash中接收网页传递过来的参数

28
29
<?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"  creationComplete= "application1_creationCompleteHandler(event)"  pageTitle= >
     <s:layout>
<s:BasicLayout/>
</s:layout>
<fx:Script>
<![CDATA[
             import  mx.core.FlexGlobals;
mx.events.FlexEvent;
 
protected  function  application1_creationCompleteHandler(event:FlexEvent): void
{
para: Object  = FlexGlobals.topLevelApplication.parameters;
</span>             text1.text = para. 1;
text2.text = para. 2;
}
 
]]>
</fx:Script>
<fx:Declarations>
<!-- 将非可视元素(例如服务、值对象)放在此处 -->
</fx:Declarations>
<s:TextInput id= "text1"  x= "190"  y= "93" />
"text2"  "142" />
<s:Label x= "147"  "94"  text= "var1:" />
"142"  "var2:" />
</s:Application>

参数在Flex4的获取方式跟Flex3是不一样的:

Flex3:  var params:Object = Application.application.parameters; 

Flex4:  var params:Object = FlexGlobals.topLevelApplication.parameters; 

相关文章

一:display:flex布局display:flex是一种布局方式。它即可以...
1. flex设置元素垂直居中对齐在之前的一篇文章中记载过如何...
移动端开发知识点pc端软件和移动端apppc端软件是什么,有哪些...
最近挺忙的,准备考试,还有其他的事,没时间研究东西,快周...
display:flex;把容器设置为弹性盒模型(设置为弹性盒模型之后...
我在网页上运行了一个Flex应用程序,我想使用Command←组合键...