Communicating between a JSP and Flex application

As part of Flex development, we had designed our UI in such a way that, there was a Main Action class which used to re-direct to Main.jsp. In this JSP, we had included the SWF file in Object tag which would load the Flex application for us. We had a requirement to pass the user-details to the Flex application from this very JSP rather than making an explicit call from Flex. In addition, we also had a requirement to set this data globally to all the Flex screens. We achieved this by following the below steps:

a) Set the User details in HttpSession or HttpRequest as an attribute or header variable
b) Make use of “FlashVars” attribute in Flash and set the parameters in the Main.jsp in a Java-Script block as shown below:

var userName= '';
var flashvars = 'userName='+userName;

c) Include flashVars while embedding the Flash Content SWF

"src", "MyApplication",
"width", "100%",
"height", "100%",
"align", "middle",
"id", "MyApplicationId",
"quality", "high",
"bgcolor", "#869ca7",
"name", "MyApplicationName",
"type", "application/x-shockwave-flash",
"pluginspage", "",
"FlashVars", flashvars

d) Include it in the Object Tag of the JSP page under tag

<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
			id="MyApplicationId" width="100%" height="100%"
			<param name="movie" value="MyApplication.swf" />
			<param name="quality" value="high" />
			<param name="bgcolor" value="#869ca7" />
			<param name="allowScriptAccess" value="sameDomain" />
			<param name="FlashVars" value="" />
			embed src="MyApplication.swf" quality="high" bgcolor="#869ca7"
				width="100%" height="100%" name="MyApplicationName" align="middle"

e) Access the ‘FlashVars’ in mxml file as shown below in the Header.mxml:

<s:Label text="{FlexGlobals.topLevelApplication.parameters.userName}, {resourceManager.getString('resources','Welcome')}"/>

f) Finally, dont forget to include the import statement in the Header.mxml

import mx.core.FlexGlobals

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s