加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

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

发布时间:2020-12-15 03:42:59 所属栏目:百科 来源:网络整理
导读:使用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" ?

使用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" "flashContent" "100%" ???????????????? 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 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>
!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;?

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读