| By Yakov Fain | Article Rating: |
|
| October 12, 2006 07:30 AM EDT | Reads: |
66,061 |
Here's the assignment: write a Flex application that can run against different servers (dev, uat, prod) without the need to recompile the SWF file. 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:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute"
applicationComplete="initApp()">
<mx:Label text=
"Will run the app deployed at http://{serverURL}:{port}/MyGreatApp.html" />
<mx:Script>
<![CDATA[
[Bindable]
var serverURL:String;
[Bindable]
var port:String;
function initApp():void{
serverURL=Application.application.parameters.serverURL;
port=Application.application.parameters.port
}
]]>
</mx:Script>
</mx:Application>
The script portion of this code gets the values of parameters serverURL and port (defined by us) using the Application object. We’ll add the values of these parameters to the HTML file as described below. These values are bound to the mxml label as a part of the text string.
If you’ll open generated HTML file, you’ll find the JavaScript function AC_FL_RunContent that includes flashVars parameters in a form of key-value pairs. For example, in my sample application it looks like this:
"flashvars",'historyUrl=history.htm%3F&lconid=' + lc_id +’’
Add our parameters serverURL and port to this string:
"flashvars",'serverURL=MyDevelopmentServer&port=8181&historyUrl=history.htm%3F&lconid=' + lc_id
Run the application, and it’ll display the URL of the server it connects to. If you’d like to test your application against QA server, just change the values of the flashVars parameters in the HTML file.
We have one last little wrinkle to iron out: if you’ll manually change the content of the generated HTML file, next time you clean the project in Flex Builder, its content will be overwritten and you’ll lose added flashVars parameters. Here’s a simple solution to this problem: instead of adding flashVars parameters to the generated HTML, add them to the file index.template.html from the html-template directory, which Flex Builder uses for generation of run and debug versions of HTML wrapper.
Of course, this little example does not connect to any server, but it gives you an idea how to pass the server URL (or any other value) as a parameter to Flash Player 9, and how to assemble the URL from a mix of text and bindings
Published October 12, 2006 Reads 66,061
Copyright © 2006 SYS-CON Media, Inc. — All Rights Reserved.
Syndicated stories and blog feeds, all rights reserved by the author.
More Stories By Yakov Fain
Yakov Fain is a Managing Director of Farata Systems, consulting, training and product company. He has authored several Java books, dozens of technical articles. SYS-CON Books released his latest co-authored book , Rich Internet Applications with Adobe Flex and Java: Secrets of the Masters in Spring 2007. Sun Microsystems has nominated and awarded Yakov with the title Java Champion. He leads the Princeton Java Users Group. He is an Adobe Certified Flex Instructor. Yakov co-athored the O'Reilly book "Enterprise Application Development with Flex". He twits at twitter.com/yfain.
![]() |
Add News 03/09/08 03:54:44 PM EDT | |||
Passing parameters this way is quite simple. Thanks. |
||||
- Cloud People: A Who's Who of Cloud Computing
- Cloud Expo New York Speaker Profile: Dave Linthicum – Cloud Technology Partners
- Cloud Expo New York Speaker Profile: Jill T. Singer – Federal CIO Emeritus
- New Relic Q1 2013 Blazes Past Growth Targets and Reaches 40,000 Active Customer Accounts
- CollabNet and UC4 Announce General Availability of Joint Enterprise DevOps Platform
- How Can Green Web Hosting Benefit Your Business?
- Big Data Isn’t About the Database, It’s About the Application
- Session Topics: 12th Cloud Expo / Cloud Expo New York
- BEA Updates WebLogic SOA Portal for Web 2.0 Era
- UNIT4 Business Software: Three Retail Accounting Tips to Help Retailers Leverage the Cloud and Back Office Systems
- Cloud Expo NY: Best Practices for Architecting Your Cloud Infrastructure
- The Rise of the Thin Client
- Cloud People: A Who's Who of Cloud Computing
- Cloud Expo New York Speaker Profile: Dave Linthicum – Cloud Technology Partners
- Cloud Expo New York Speaker Profile: Jill T. Singer – Federal CIO Emeritus
- Enterasys Spotlights SDN's Impact on Traditional Networking in Upcoming Webinar
- New Relic Q1 2013 Blazes Past Growth Targets and Reaches 40,000 Active Customer Accounts
- CollabNet and UC4 Announce General Availability of Joint Enterprise DevOps Platform
- How Can Green Web Hosting Benefit Your Business?
- Big Data Isn’t About the Database, It’s About the Application
- Upcoming Bloomberg BNA Webinar Focuses on COPPA Compliance
- NASA's Twitter Account Wins Back-To-Back Shorty Awards
- Session Topics: 12th Cloud Expo / Cloud Expo New York
- Cloud Expo New York: Basics of SSD Technology and Its Use in Cloud
- The Top 150 Players in Cloud Computing
- Who Are The All-Time Heroes of i-Technology?
- Where Are RIA Technologies Headed in 2008?
- Success, Arrogance, Rise and Fall
- AJAX World RIA Conference & Expo Kicks Off in New York City
- Personal Branding Checklist
- The Top 250 Players in the Cloud Computing Ecosystem
- i-Technology Viewpoint: Attack of the Blogs
- Exclusive Q&A with Jeff Haynie, Co-Founder & CEO, Appcelerator
- Web 2.0 News and Wrapping Up "Real-World AJAX" Seminar
- Passing Parameters to Flex That Works
- i-Technology Viewpoint: It's Time to Take the Quotation Marks Off "Web 2.0"





















