Passing request data with flashVars properties

Passing request data with flashVars properties

If you are using the generated wrapper from Flash Builder, then you add flashVars variables by creating an object called flashvars, setting properties on that object, and then passing that object to the swfobject.embedSWF() method of SWFObject 2.

The following example sets the  firstname and  lastname properties of the flashvars object, and then passes that object to the  embedSWF() method:
<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"; 
    swfobject.embedSWF( 
        "FlashVarTest.swf", "flashContent", "100%", "100%", swfVersionStr, 
        xiSwfUrlStr, flashvars, params, attributes); 
    swfobject.createCSS("#flashContent", "display:block;text-align:left;"); 
</script>

If your wrapper uses the <object> and <embed> tags, you can pass variables to your applications by using the flashVars properties in the <object> and <embed> tags in your wrapper. You do this by adding ampersand-separated sets of name-value pairs to these properties.

The following example sets the values of the firstname and lastname in the flashVars properties inside the <object> and <embed> tags in a simple wrapper:

<html>
<head>
<title>code/wrapper/SimplestFlashVarTestWrapper.html</title>
<style>
    body {
        margin: 0px;
        overflow:hidden
    }
</style>
</head>
<body scroll='no'>
<table width='100%' height='100%' cellspacing='0' cellpadding='0'><tr><td valign='top'>

<h1>Simplest FlashVarTest Wrapper</h1>

    <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>

</td></tr></table>
</body>
</html>

The value of the flashVars properties do not have to be static. If you use JSP to return the wrapper, for example, you can use any JSP expression for the value of the flashVars properties that can be evaluated to a String.

The following example uses the values stored in the HttpServletRequest object (in this case, you can use form or query string parameters):

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<!-- saved from url=(0014)about:internet -->

<%
    String fName = (String) request.getParameter("firstname");
    String lName = (String) request.getParameter("lastname");
%>

<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
    <head>
        <title>DynamicFlashVarTestWrapper.jsp</title>
        <script type="text/javascript" src="swfobject.js"></script>
        
        <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>
    </head>

    <body>
        <div id="flashContent"/>
   </body>
</html>
You can also PHP expressions to pass query string parameters in a wrapper, as the following example shows:
<!-- saved from url=(0014)about:internet --> 
<html lang="en"> 
<head> 
<?php 
    @ $fName = $_GET['firstname']; 
    @ $lName = $_GET['lastname']; 
?> 
<script type="text/javascript" src="swfobject.js"></script> 
<script type="text/javascript"> 
    var swfVersionStr = ""; 
    var xiSwfUrlStr = ""; 
    var flashvars = {}; 
    flashvars.fName = "<?php echo $fName; ?>" 
    flashvars.lName =  "<?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> 
</head> 
<body > 
    <div id="flashContent"> 
</body> 
</html>

For more information about the HTML wrapper, see Creating a wrapper.

If your user requests the SWF file directly in the browser, without a wrapper, you can access variables on the query string without providing additional code in the wrapper (because there is no wrapper). The following URL passes the name Nick and the hometown San Francisco to the application:

http://localhost:8100/flex/myApp.swf?myName=Nick&myHometown=San%20Francisco
About flashVars properties encoding

The values of the flashVars properties must be URL encoded. The format of the string is a set of name-value pairs separated by an ampersand (&). You can escape special and nonprintable characters with a percent symbol (%) followed by a two-digit hexadecimal value. You can represent a single blank space by using the plus sign (+).

The encoding for flashVars properties is the same as the page. Internet Explorer provides UTF-16-compliant strings on the Windows platform. Netscape sends a UTF-8-encoded string to Flash Player.

Most browsers support a flashVars string or query string up to 64 KB (65535 bytes) in length. They can include any number of name-value pairs.

Using the SWF file path to pass request data

You can append the values of properties to the application’s SWF file path in the wrapper. The swfUrlStr property identifies the location of the application’s SWF file. It is the first argument in theswfobject.embedSWF() method call.

The following example appends query string parameters to the  swfUrlStr properties in the custom wrapper:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<!-- saved from url=(0014)about:internet -->
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
    <head>
        <title>wrapper/SwfObjectWithFlashVars.html</title>
        <script type="text/javascript" src="swfobject.js"></script>
        <script type="text/javascript">
            var swfVersionStr = "0";
            var xiSwfUrlStr = "";
            var flashvars = {};
            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?firstname=Nick&lastname=Danger",
                "flashContent", "100%", "100%",
                swfVersionStr, xiSwfUrlStr,
                flashvars, params, attributes);
        </script>
    </head>
    <body>
        <div id="flashContent"/>
   </body>
</html>

Variables you define in this manner are accessible in the same way as flashVars properties. For more information, see Accessing the flashVars properties.

Accessing the flashVars properties

To access the values of the flashVars properties, you use the FlexGlobals object’s topLevelApplication.parameters property. This property points to a dynamic object that stores the parameters as name-value pairs. You can access variables on the parameters object by specifying parameters.variable_name.

In your application, you typically assign the values of the run-time properties to local variables. You assign the values of these properties after the Application’s creationComplete event is dispatched. Otherwise, the run-time properties might not be available when you try to assign their values to local variables.

The following example defines the myName and myHometown variables and binds them to the text of Label controls in the initVars() method:

<?xml version="1.0" encoding="utf-8"?>
<!-- wrapper/ApplicationParameters.mxml -->
<s:Application 
    xmlns:fx="http://ns.adobe.com/mxml/2009" 
    xmlns:mx="library://ns.adobe.com/flex/mx" 
    xmlns:s="library://ns.adobe.com/flex/spark" creationComplete="initVars()">
     <s:layout> 
          <s:VerticalLayout/> 
     </s:layout>
     
       <fx:Script><![CDATA[
          import mx.core.FlexGlobals;
       
          /* Declare bindable properties in Application scope. */
          [Bindable]
          public var myName:String;
          [Bindable]
          public var myHometown:String;
           
          /* Assign values to new properties. */
          private function initVars():void {
               myName = FlexGlobals.topLevelApplication.parameters.myName;
               myHometown = FlexGlobals.topLevelApplication.parameters.myHometown;
          }
     ]]></fx:Script>
       
     <s:HGroup>
          <s:Label text="Name: "/>
          <s:Label text="{myName}" fontWeight="bold"/>
     </s:HGroup>
     
     <s:HGroup>
           <s:Label text="Hometown: "/>
           <s:Label text="{myHometown}" fontWeight="bold"/>
     </s:HGroup>
</s:Application>

When a user requests this application with the myName and myHometown parameters defined as flashVars properties or as query string parameters, Flex displays their values in the Label controls.

To view all the  flashVars properties, you can iterate over the  FlexGlobals.topLevelApplication.parameters properties, as the following example shows:
<?xml version="1.0" encoding="utf-8"?>
<!-- wrapper/FlashVarTest.mxml -->
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
    xmlns:mx="library://ns.adobe.com/flex/mx" 
    xmlns:s="library://ns.adobe.com/flex/spark" 
    creationComplete="init()">
     
     <s:layout> 
        <s:HorizontalLayout/> 
     </s:layout>
     
     <fx:Script><![CDATA[
         import mx.core.FlexGlobals;

         private function init():void {
              for (var i:String in FlexGlobals.topLevelApplication.parameters) {
                 ta1.text += i + ":" + FlexGlobals.topLevelApplication.parameters[i] + "/n";
              }
          }
      ]]></fx:Script>
       
      <s:Label text="flashVars"/>
      <s:RichText id="ta1" width="300" height="200"/>

</s:Application>
 
   
 
   
 
   
 
   
Adobe Link : http://help.adobe.com/en_US/flex/using/WS2db454920e96a9e51e63e3d11c0bf626ae-7feb.html

内容概要:本研究聚焦于绿电直连型电氢氨园区的优化运行,提出一种集成绿色电力直接供给、电解水制氢及氢气合成氨工艺的综合能源系统架构。通过建立包含风光发电、电解槽、氨合成反应器、储氢罐、电网交互及多类型负荷在内的系统模型,综合考虑绿电直供优先、能量梯级利用与多能互补原则,构建以系统综合运行成本最小化为目标的优化调度模型。研究采用Matlab与Python工具进行算法求解和仿真分析,利用实际气象与负荷数据完成案例验证,评估了不同运行策略下系统的经济性、可再生能源消纳能力与碳减排效益,为新型电氢氨一体化园区的规划与运行提供了理论依据和技术支撑。; 适合人群:具备一定电力系统、新能源或化工背景的研究生、科研人员及从事综合能源系统规划与优化工作的工程技术人员。; 使用场景及目标:①用于科研学习,理解电-氢-氨多能转换系统的建模与优化方法;②为工业园区的低碳化、智能化改造提供技术参考与决策支持;③作为开发类似综合能源管理系统的理论基础。; 阅读建议:此资源包含完整的模型代码、数据与论文,使用者应结合代码仔细研读论文中的模型构建部分,重点关注目标函数与约束条件的设计逻辑,并尝试修改参数进行仿真,以深入掌握优化算法在实际系统中的应用。
内容概要:本文深入探讨了RS485通信协议在芯片行业自动化测试系统中的实际开发与应用,涵盖其关键概念、电气特性、通信机制及与Modbus RTU协议的结合使用。文章重点介绍了差分信号完整性设计、主从时序控制、CRC校验与重传机制等核心技术要点,并通过一个基于Python的完整代码实例,展示了如何实现RS485主站对探针台、自动分选机等芯片测试设备的控制与数据采集。此外,还分析了RS485在晶圆探针台、ATE设备集群和环境监控等典型场景的应用,并展望了其与工业以太网融合、智能化诊断、高速化及AI集成的发展趋势。; 适合人群:具备一定嵌入式系统或工业通信基础,从事芯片测试、自动化设备开发及相关领域的研发人员,尤其是工作1-3年希望提升现场总线应用能力的工程师。; 使用场景及目标:①理解RS485在高干扰芯片测试环境中稳定通信的设计原理;②掌握Modbus RTU协议在Python下的实现方法,用于实际控制探针台、Handler等设备;③构建可靠的数据采集与设备控制系统,支持CRC校验、异常处理和日志追踪;④为后续向高速通信和智能诊断系统升级提供技术储备。; 阅读建议:此资源强调实战开发,建议结合硬件环境动手调试代码,重点关注线程锁、CRC计算、帧解析和超时控制等关键环节,在真实产线中验证通信稳定性,并利用日志系统进行故障分析与优化。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值