Quantcast

FlashVars in Flex

Get the WebProNews Newsletter:
[ Business]

Last month I wrote an article about how to use FlashVars in a Flex application.

FlashVars are simple values passed in to the Flash movie from the HTML/JavaScript that embeds the SWF. I thought I’d follow it up with a practical example on an application I’m working on right now.

I’m building an administrator interface for a web site. This application will make use of Flash Remoting to talk to a CFC. The path to the CFC isn’t hard coded though. To make matters worse, my dev environment isn’t exactly like production. Therefore, the “dot path” location of the CFC needs to be dynamic. I decided to pass in the path via FlashVars.

I had things working on the Flex side, hard coded, so the first thing I did was to remove the source attribute from my RemoteObject tag:

<mx:RemoteObject id="core" destination="ColdFusion" showBusyCursor="true" >

My Flex code was already running code on creationComplete:

<mx:VBox xmlns:mx=”http://www.adobe.com/2006/mxml” width=”100%” height=”100%” xmlns:views=”views.*” creationComplete=”init()” >

So I simply updated my init() function:

private var componentroot:String = "";

private function init():void {
   componentroot = this.parameters.componentroot;
   core.source = componentroot + "components.admin";
}

As I mentioned in the previous entry, the data from the FlashVars is available as this.parameters.name, where name is the FlashVar name.

So how do I test this? One of the cool things about FlexBuilder is that you can modify the HTML generated when you view your application. I went into the html-template folder, opened up index.template.html, and changed this line:

"flashvars",'historyUrl=history.htm%3F&lconid=' + lc_id + '',

To this:

"flashvars",'componentroot=secretproject.server.&historyUrl=
history.htm%3F&lconid='+ lc_id + '',

This isn’t the final step though. I’m deploying to a site running ColdFusion. I’ll eventually change my index.html file to an index.cfm file and use an Application variable for the component root.

So now I have a problem. The this.parameters structure only exists for the core Flex file of an application, not the children.

How can I get my children to also use the value? I’m thinking what I’ll do is pass the value from parent to child, since that is relatively easy to do.

I could make the child run code to grab it from the parent, but that is such a pain to do. (More on that later.) I don’t want to have to create a custom even just to read a simple value from the parent. (But that may just be me being lazy. :)

Comments

Tag:

Add to Del.icio.us | Digg | Reddit | Furl

Bookmark WebProNews:

Raymond Camden, ray@camdenfamily.com
http://ray.camdenfamily.com

Raymond Camden is Vice President of Technology for roundpeg, Inc. A long
time ColdFusion user, Raymond has worked on numerous ColdFusion books
and is the creator of many of the most popular ColdFusion community web
sites. He is an Adobe Community Expert, user group manager, and the
proud father of three little bundles of joy.

FlashVars in Flex
About Raymond Camden
Raymond Camden, ray@camdenfamily.com
http://ray.camdenfamily.com

Raymond Camden is Vice President of Technology for roundpeg, Inc. A long time ColdFusion user, Raymond has worked on numerous ColdFusion books and is the creator of many of the most popular ColdFusion community web sites. He is an Adobe Community Expert, user group manager, and the proud father of three little bundles of joy. WebProNews Writer
Top Rated White Papers and Resources
  • http://yasob.blogspot.com Nash

    http://yasob.blogspot.com/2009/05/accessing-http-request-parameter-in.html

  • Jose

    I need to run swf from Java (swing) application. The swf has to load an xml file, which can be different each time. The way I’m doing it is using a bat file. I mean, from Java I call a bat file and this bat file call the swf. But the problem I have is that I dont know how let the swf know which xml file has to load. My idea was pass the xml file name as a parameter to swf, but didnt work. Currently, the swf call a harcoded name of xml. So always the same xml file is loaded. Can anybody give a hand? Thanks in advance!

  • Jose

    I need to run swf from Java (swing) application. The swf has to load an xml file, which can be different each time. The way I’m doing it is using a bat file. I mean, from Java I call a bat file and this bat file call the swf. But the problem I have is that I dont know how let the swf know which xml file has to load. My idea was pass the xml file name as a parameter to swf, but didnt work. Currently, the swf call a harcoded name of xml. So always the same xml file is loaded. All files are local and in the same directory. Can anybody give a hand? Thanks in advance!