Recently I wrote a blog post about the differences between ActionScript 3.0 and ActionScript 2.0. One major difference that I found and dealt with had been lost in my unordered notes of what I wanted to write about;

Passing parameters to Flash.
Why would you want to that? Consider the case that your website consists of one giant swf file (and there are valuable reasons to have such a website). Off course the swf will probably be embedded inside a HTML page that links the swf content to some meta data and offers some alternative HTML content for the visitor that have no Flash plugin for their browser, but the content that you want to show to the visitor is all trapped inside that swf file. If for example you had blog content inside that swf, it would kind of suck that you have no means for giving friends URLs to directly jump to a specific blog post inside that swf similar to what you achieve with permalinks in HTML blogs. (I can for example give people the hyperlinks to blogging-in-flash or findability-and-linkability-with-flash to directly point them to what I want them to read about.) And this is just one example of why you would want a way of “indexing your swf”/”generate your swf based on parameters”.

So here it is then. A short explanation of implementing parameter passing to an ActionScript 3.0 swf. It still is as simple as having your browser request the swf file with extra parameters folowing the name of the file. Like this; name_of_your.swf?param1=value1&param2=value2&param3=value3 etc… this part hasn’t changed. But getting access to the passed parameters has. In ActionScript 2 you used to have global access to the parameters as they where added as variables to the _root namespace. Now it’s slightly different, they’re now stored in the loaderInfo of the Stage object. (So it’s only accessible from the Stage object itself or members of it’s display tree.
Here’s example code reading the variables;

var keyStr:String;
var valueStr:String;
var paramObj:Object = LoaderInfo(this.root.loaderInfo).parameters;
for (keyStr in paramObj) {
valueStr = String(paramObj[keyStr]);
//do something with this information
}

Something else
There’s something else that slightly touches this subject. Use the Adobe Flash Player version detection kit. The flash 9 player is taken over the old players but not everyone is having the new player yet. Be sure to detect this and gently notify your visitors of the need to update their Flash plugin. That’s so much better then seeing nothing or an incorrectly functioning website! The kit provides of examples of it’s use but it might confuse you of where to insert the Flash parameters into the JavaScript function call that generates the embedded Flash object. Just add the parameters in the src string tuple (‘src’, ‘your_swf_location‘), you can omit the .swf file extension here.

For example this is the javascript (generated from a server side script) function call that embeds the Studio Roosegaarde 2.0 swf with parameter blog_item(=15);

if(hasRightVersion) { // if we’ve detected an acceptable version
// embed the flash movie
AC_FL_RunContent(
‘width’, ‘100%’,
‘height’, ‘100%’,
src‘, ‘StudioRoosegaarde2?blog_item=15‘,
‘quality’, ‘best’,
‘pluginspage’, ‘http://www.macromedia.com/go/getflashplayer’,
‘name’, ‘StudioRoosegaarde2’,
‘allowScriptAccess’,’sameDomain’,
‘allowFullScreen’,’true’
); //end AC code
}

Laptop alarm

July 6, 2007

You might like this. I know I do.

A friend of mine, Yoram, build this really simple software laptop alarm. I tested it out myself and I think it will work quite effective!

Why would you want to have this? I don’t know. Here’s an example of where I’m going to use it for sure; my universities central library. It’s one of those places along with lecture rooms and the restaurants at the TU Delft University where I have enough trust in the people walking around to allow myself some distance between me and my laptop for example to get some fresh air, go to the toilet or get myself a coffee. But of course it takes one evil person and a little bit of time to steal a laptop and chances are that no one will even notice anything unusual in that process. Everyone is carying around laptops and now one is keeping track of which is whose. But the situation is totally different when the laptop being stolen screams alarm alarm alarm at it’s loudest volume!

This is where “laptop alarm” comes in.

Laptop alarm

Yoram is probably still tweaking and working on it as I write this. I’ve seen it upgrade just now from version 1beta to a version 1.1beta. Here’s what the alarm looked like the last time I checked. A small, clean and elegant interface with no more buttons then just the one you need “Lock computer”.

Laptop Alarm

The program consists of one small executable of 188kb. I have mine on my desktop. When I leave my laptop I double click it and chose which events I want to fire the alarm. I lock my computer by pressing the “Lock Computer” button and it goes into standby mode. If someone now want to snatch my laptop and run away with it, he will most likely have to disconnect it from the power supply and unplug the mouse. Laptop alarm will now crank up the volume to it’s maximum and play the alarm tune. This will alarm by standers and hopefully the villain will either be caught or escape in distress while leaving my laptop behind. Of course you can just unlock your laptop by getting it out of the standby mode. (So be sure to protect that action with a password.) Nifty isn’t!

I like the idea. And so simple. Just a software solution. My thoughts are running wild with ideas of extra features. What would you like to see added to Laptop Alarm?