关闭

Flex4中将网页的参数传递给Flash,并且在Flash中读取这些参数,以及flash接收网页传过来的值

标签: FLEX 4
299人阅读 评论(0) 收藏 举报
分类:

使用flashvars将参数通过网页传递给Flash

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

方式一(swfobject):

<script type="text/javascript">
            <!-- For version detection, set to min. required Flash Player version, or 0 (or 0.0.0), for no version detection. --> 
            var swfVersionStr = "10.0.0";
            <!-- To use express install, set to playerProductInstall.swf, otherwise the empty string. -->
            var xiSwfUrlStr = "playerProductInstall.swf";
            <span style="color: #000000;">
<span style="white-space:pre">		</span>var flashvars = {var1:"abc",var2:"def"};
<span style="white-space:pre">	</span>    </span>            
<span style="white-space:pre">		</span>var params = {};
<span style="white-space:pre">		</span>params.quality = "high";
<span style="white-space:pre">		</span>params.bgcolor = "#ffffff";
<span style="white-space:pre">		</span>params.allowscriptaccess = "sameDomain";
            params.allowfullscreen = "true";
            var attributes = {};
            attributes.id = "test39";
            attributes.name = "test39";
            attributes.align = "middle";
            swfobject.embedSWF(
                "test39.swf", "flashContent", 
                "100%", "100%", 
                swfVersionStr, xiSwfUrlStr, 
                flashvars, 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):

<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="100%" height="100%" id="test39">
                <param name="movie" value="demo1.swf" />
                <param name="quality" value="high" />
                <param name="bgcolor" value="#ffffff" />
                <param name="allowScriptAccess" value="sameDomain" />
                <param name="allowFullScreen" value="true" />
                <span style="color: #000000;">
<span style="white-space:pre">			</span><param name="flashvars" value="var1=aabb&var2=ccdd" />
<span style="white-space:pre">			</span></span>               
<span style="white-space:pre">			</span> <!--[if !IE]>-->
                <object type="application/x-shockwave-flash" data="demo1.swf" width="100%" height="100%">
                    <param name="quality" value="high" />
                    <param name="bgcolor" value="#ffffff" />
                    <param name="allowScriptAccess" value="sameDomain" />
                    <param name="allowFullScreen" value="true" />
                    <param name="flashvars" value="var1=aabb&var2=ccdd" />
                <!--<![endif]-->
                <!--[if gte IE 6]>-->
                    <p> 
                        Either scripts and active content are not permitted to run or Adobe Flash Player version
                        10.0.0 or greater is 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>
                <!--[if !IE]>-->
                </object>
                <!--<![endif]-->
            </object>

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

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

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

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

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


0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:14845次
    • 积分:209
    • 等级:
    • 排名:千里之外
    • 原创:3篇
    • 转载:16篇
    • 译文:0篇
    • 评论:0条
    文章分类