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: 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;");
  If your wrapper uses the and tags, you can pass variables to your applications by using the flashVars properties in the and 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 and tags in a simple wrapper: code/wrapper/SimplestFlashVarTestWrapper.html body { margin: 0px; overflow:hidden } height='100%' cellspacing='0' cellpadding='0'> Simplest FlashVarTest Wrapper height='100%' width='100%'> height='100%' width='100%' flashVars='firstname=Nick&lastname=Danger'/>
  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): DynamicFlashVarTestWrapper.jsp var swfVersionStr = "0"; var xiSwfUrlStr = ""; var flashvars = {}; flashvars.firstname = ""; flashvars.lastname = ""; 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);
  You can also PHP expressions to pass query string parameters in a wrapper, as the following example shows: var swfVersionStr = ""; var xiSwfUrlStr = ""; var flashvars = {}; flashvars.fName = "" flashvars.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;");
  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: [b]About flashVars properties encoding [/b]
  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. 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: wrapper/SwfObjectWithFlashVars.html 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);
  Variables you define in this manner are accessible in the same way as flashVars properties. For more information, see 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: flex/mx" xmlns:s="library://ns.adobe.com/flex/spark" creationComplete="initVars()">
  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: flex/mx" xmlns:s="library://ns.adobe.com/flex/spark" creationComplete="init()"> height="200"/> Adobe Link : http://help.adobe.com/en_US/flex/using/WS2db454920 e96a9e51e63e3d11c0bf626ae-7feb.html
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值