| Flex 2 Developer's Guide > Flex Programming Topics > Communicating with the Wrapper > Passing request data to Flex applications > Using flashVars | |||
You can pass variables to your Flex applications using the flashVars properties in the <object> and <embed> tags in your wrapper.
The following example sets the values of the firstname, middlename, and lastname flashVars properties inside the <object> tag in a simple wrapper:
<html>
<head>
<title>/flex2/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' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0' height='100%' width='100%'>
<param name='src' value='FlashVarTest.swf'/>
<param name='flashVars' value='firstName=Nick&lastName=Danger'/>
<embed name='mySwf' src='FlashVarTest.swf' pluginspage='http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash' height='100%' width='100%' flashVars='firstName=Nick&lastName=Danger'/>
</object>
</td></tr></table>
</body>
</html>
If you are using the wrapper that is generated by Flex Data Services or wrappers that are included in the resources/html-templates directory, your wrapper might not look the same, but the basic approach to passing the flashVars variable is. For example, you might insert flashVars variables by appending them to a function parameter, as the following example shows:
"flashvars","historyUrl=%2Fflex%2Fflex%2Dinternal%3Faction%3Dhistory%5Fhtml&lconid=" + lc_id + "&firstName=Nick&lastName=Danger",
The value of the flashVars variable does 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 variable 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):
<html>
<head>
<title>/flex2/code/wrapper/DynamicFlashVarTestWrapper.jsp</title>
<style>
body { margin: 0px;
overflow:hidden }
</style>
</head>
<%
String fName = (String) request.getParameter("firstname");
String mName = (String) request.getParameter("middlename");
String lName = (String) request.getParameter("lastname");
%>
<body scroll='no'>
<table width='100%' height='100%' cellspacing='0' cellpadding='0'><tr><td valign='top'>
<script>
<h1>Dynamic FlashVarTest Wrapper</h1>
</script>
<object id='mySwf' classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0' height='100%' width='100%'>
<param name='src' value='../assets/FlashVarTest.swf'/>
<param name='flashVars' value='firstname=<%= fName %>&lastname=<%= lName %>'/>
<embed name='mySwf' src='../assets/FlashVarTest.swf' pluginspage='http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash' height='100%' width='100%' flashVars='firstname=<%= fName %>&lastname=<%= lName %>'/>
</object>
</td></tr></table>
</body>
</html>
Flex 2.01
Send me an e-mail when comments are added to this page | Comment Report
Current page: http://livedocs.adobe.com/flex/201/html/passingarguments_086_05.html