Today’s assignment is to be able to run a Flex application against different servers (dev, uat, prod) without the need to recompile SWF. It does not take a rocket scientist to figure out that the URL of the server should be passed to SWF as a parameter, and we’ll do this by using a special variable flashVars in HTML wrapper. Flex documentation suggests to include flashVars parameters in the tags Object and Embed and read them using Application.application.parameters in AS3 code. At the time of this writing this does not work. But as the ancient saying goes, “Adobe closes one door but opens another”. Let’s get familiar with Flex code:


Campbell said,
October 12, 2006 @ 7:44 am
I had a client call up to fix a 4 year old flash app because there was an issue with the flash vars and the latest version of the player (possibly the latest point release). Something has also changed in the player me thinks.
Aaron West said,
October 14, 2006 @ 9:41 am
All, I’m digging the blog and getting a lot out of your Flex content. However, I’m curious about this latest post dealing with FlashVars, especially considering I have an app that uses the Application.application.parameters.varname method and it works just fine. To elaborate, I’m using the SWFObject JavaScript API to embed the Flash movie in the Web page dynamically (good ole Active Content fix for IE). I have a property in the SWFObject code that gets passed in as a FlashVar. In Flex, I’ve defined an initializeApp() function that is set to execute on the creationComplete event of the entire Flex app. Inside the initializeApp() function I simply reference the variable that was passed with FlashVars. It works like a charm.
Yakov Fain said,
October 14, 2006 @ 11:47 am
In my example I also use flashVars values in the JavaScript function and it works. But Flex doc states that flashVars should work fine when used in HTML Object and Embed tags. This part did not work for me.
Aaron West said,
October 15, 2006 @ 5:15 pm
So perhaps the problem is only apparent when embedding your SWF’s with and tags.
Aaron West said,
October 15, 2006 @ 5:16 pm
oops, the HTML was stripped… should’ve read: “…your SWF’s with the actual “object” and “embed” tags.”
Cristian Pop said,
October 31, 2006 @ 6:04 am
What about reading URL from zml config files, maybe something like resource in Java, has anyone tried this ?
Tom Chiverton said,
November 1, 2006 @ 5:57 am
We’re using the SWFObject wrapper to present Flex apps in HTML pages, and it’s passing FlashVars fine.
Daniel Rosenstark said,
December 7, 2006 @ 6:17 pm
Flashvars most definitely work. We use them to locate the WSDL, which is quite different on development and production servers. Also, we use them for debug parameters (different HTML code, but the SWF doesn’t need a recompile).
More interestingly, we’ve just implemened a “hack” (not really) to pull parameters off the URL in an ASPX page and then “push” them onto the SWF flashvars. This is useful if you want your Flex app to react to URLs. For instance, your Flex app reacts to “permalinks”… Flex rocks.
We don’t even let users load the .swf without Javascript (so we don’t use the object embed tags). According to our latest webstats, that’s deterred very few users.
Daniel Rosenstark
ceo [at] thekbase.com
See the Walkthrough for TheKBase Web (www.kbaseweb.com)
“Organize Your Data EVERY Way You Want To”
Nash said,
June 1, 2009 @ 3:10 pm
few ways to pass variable to flex
http://yasob.blogspot.com/2009/05/accessing-http-request-parameter-in.html