Passing the Browser Query String to a Flex 4 Application

Passing parameters into a Flex 4 (Beta 2) application is slightly different to passing parameters into a Flex 3 application. Previously you would pass a string into the flashvars parameter with the key/value pairs, now you pass in an associative array with the key/value pairs.

In the launcher HTML template file you will see the following javascript:

var swfVersionStr = "${version_major}.${version_minor}.${version_revision}";
var xiSwfUrlStr = "${expressInstallSwf}";
var flashvars = {};
var params = {};
params.quality = "high";
params.bgcolor = "${bgcolor}";
params.allowscriptaccess = "sameDomain";
params.allowfullscreen = "true";
var attributes = {};
attributes.id = "${application}";
attributes.name = "${application}";
attributes.align = "middle";
swfobject.embedSWF(
	"${swf}.swf", "flashContent", 
	"${width}", "${height}", 
	swfVersionStr, xiSwfUrlStr, 
	flashvars, params, attributes);
swfobject.createCSS("#flashContent", "display:block;text-align:left;");

As you can see the flashvars and params are now passed into the Flash object as associative arrays, and the method that is called on the Flash object is no longer AC_FL_RunContent().

To get the query string into the flashvars object is very easy, simply iterate through the query string and add each key/value to the flashvars object.

var swfVersionStr = "${version_major}.${version_minor}.${version_revision}";
var xiSwfUrlStr = "${expressInstallSwf}";
var flashvars = {};

var queryString = window.location.search.substring(1);
if (queryString != null && queryString.length > 0)
{			
	var keyValuePairs = queryString.split("&");
	for (var i = 0; i < keyValuePairs.length; i++) 
	{
		var keyValuePair = keyValuePairs[i].split("=");
		
		if (keyValuePair.length == 2)
		{
			flashvars[keyValuePair[0]] = keyValuePair[1];
		}
	}
} 

var params = {};
params.quality = "high";
params.bgcolor = "${bgcolor}";
params.allowscriptaccess = "sameDomain";
params.allowfullscreen = "true";

var attributes = {};
attributes.id = "${application}";
attributes.name = "${application}";
attributes.align = "middle";

swfobject.embedSWF(
	"${swf}.swf", "flashContent", 
	"${width}", "${height}", 
	swfVersionStr, xiSwfUrlStr, 
	flashvars, params, attributes);
swfobject.createCSS("#flashContent", "display:block;text-align:left;");

Then to access the parameters inside your Flex application you just need to access the parameters property on the application object.

var someVariable:String = this.parameters["MyQueryStringKey"];
// OR
var someOtherVariable:String = FlexGlobals.topLevelApplication.parameters["MyQueryStringKey"];

That’s it, simple :)

Post based on Adobe Flash Builder 4 Beta 2

Google’s Go – Language Fail?

Google released a new programming language named Go recently, by the sounds of it they are hoping it will solve developer woes and make development easier. I don’t agree with their reason for creating it to start off with, from the Go FAQ page: “Go was born out of frustration with existing languages and environments for systems programming. Programming had become too difficult and the choice of languages was partly to blame.” Personally I don’t find programming difficult but maybe that’s just because I’m looking at a different set of problems than the guys behind Go.

Before I continue let me just make it clear that I’m a .NET developer (I was a Delphi developer many years ago) and a fan of the Microsoft development environment so what I have to say is influenced by my experiences with Microsoft tools and languages.

While I think it’s admirable that Google wants to simplify programming, I personally don’t see anything enticing about the language to make the move to it. These are my problems with the language in it’s current form, who knows maybe future versions will be better :)

  • No generics – I understand that it must be difficult to include generics in a compiler but come on, generics are so useful! (link)
  • No exceptions – This I don’t understand! Come on, there are meant to be some sharp guys working on this project – how can they not include exceptions?! (link)
  • No type inheritance – Now this is the one point that makes me think this language isn’t much better than VBScript. (link)
  • No overloading of method or operators – This isn’t a big deal but it would be nice. (link)

So those are my main dislikes about the language, but there are some other problems too. I thought I’d give it a try even though I wan’t keen on it so I went to the download page and you have to download the source and compile the compiler, that’s where I lost interest in Go! How hard is it to provide binaries for the most common platforms! I’m assuming that it is just a command line compiler and that there is no IDE, which is another negative.

There are two things that they have done that are cool; one is that they have build in some clever support for concurrency using CSP, and the other is that Go will be available in Chrome and as a plugin for other browsers. This could be where Go finds its niche, personally I’d like to see a language more powerful than JavaScript in the browser.

I must also mention that Go is an experimental programming language so I’m probably being a little harsh :)