A few days on PaperVision3D

So last week I had the opportunity to get my hands dirty with PaperVision3D. As mentioned previously, the company I work for has been responsible for implementing the 2008 Earth Hour website.

Well, as part of that, I had a crack at visualising the global support being given to the Earth Hour movement. Using AS3, I first load in a zipped text file containing lat/longs of each user sign up, and of those users broken down by country, which I uncompress and iterate over to create textures. I then use PaperVision3D to generate a set of spheres which I wrap the textures around, and add some simple mouse interactions.

I settled with an early release of the engine – but am keen to have a go at the 2.0 branch and see if it speeds things up.

Global Earth Hour supporters

Flash 9 player is required to view this content. It can be downloaded from Adobe.com

Earth Hour

At work we just went live with a project for Earth Hour, which began it’s life in Sydney as a 1 hour event where everyone turns their lights off – including big business. Well, this year, it’s going global. Spread the word!

http://www.earthhour.org

For those interested in the technology, we used RoR and Radiant.

A week on ActionScript 3.0

So I’ve spent about a week now hacking away at the latest incarnation of Flash ActionScript. It’s been an interesting journey, and one that is getting more and more rewarding, the longer I spend time with it. AS3 has been around for a while now, but the nature of the work that I do on a daily basis has meant that I’ve not had a. the need, and b. the opportunity to actually spend any time learning it up until now.

Late last year I spent a day looking at some tutorials, and following on with them – but the only real way I know to really learn something is to actually do it. As a self-taught slash web-taught coder, it raises interesting challenges – as you rely on other’s sharing and structure to begin the process.

As part of the learning process, I set up labs.shiftperception.com/ – which I intend to fill with useful examples (for my own future reference as much as others). As is often the case though, at the moment it belies the amount of learning i’ve undergone in just a short week. However, the process of making the labs itself gave me a great start to feeling confident approaching development using this new codebase. Some reflections:

There are some really smart people out there, ready to help.

It can be daunting at first, to realise that there are soo many really good Flash developers out there that are doing amazingly cool stuff… but as you dig deepeer, you realise that these same developers are the first to offer help, examples and understanding that quite frankly put the Adobe help files to shame. I’m quite sure some of these same people either worked closely with Adobe to develop AS3, or helped test it, and if they didn’t, they should. A few links to help the weary searcher (ive posted many of these before, but well worth doing again! bear in mind it’s non-exhaustive) :

Flash is moving away from designers, and towards developers.

I know, it’s a bold statement, but it feels true. What I mean is that, yes – for all intense and purpose, Flash CS3 still functions the same as Flash 8 and MX2004. As a designer I can still go in and add MovieClips, manipulate the timeline, and do all my usual tricks using reasonably simple AS2 code. But as soon as I want to do anything specific to AS3, simple things become a lot more difficult to understand – memory management, adding and removing event listeners, and that’s not even approaching Classes and that can of worms. These are the realms of the developer. Someone versed in the language of zero’s and one’s. Not your average Designer. Not even (for the most part) your very good designer.

This is a very interesting point, because it seems that Flash, as it becomes ubiquitous on multiple devices, and as the language matures, it is invariably becoming a true development environment, aimed less at the original target market, and more and more at the developer. And it’s a very difficult juggling act to make. I wonder how long until a completely developer-oriented version is made?

I’ve been lucky enough to have access to a mate of mine, OJ, who – while not a Flash developer, is an extremely good programmer in pretty much everything else… and the great thing (at least for me) is that, while knowing next to nothing about AS3, he’s now able to help me with my coding woes. Sure there are some Flash-specifics that he needs me to enlighten him about, and he could certainly help me with theory in older versions of AS, but because AS3 now more than ever closely resembles other standard programming languages, people with skills like his can now give advice and help to us lowly slashes.

Migrating from AS2 to AS3 is not as simple as you think.

Unless you came clean into ActionScript at version 2.0, and embraced the developer’s approach to writing code, and even if you did – some fundamental things have changed between AS2 and AS3. Like dynamically attaching a MovieClip. Like references to _root, _parent and _global. Like keyboard events. If you have a project in AS2 that uses any of these, and want to port it to AS3, depending on your competencies as a programmer, this might not be a worthwhile task.

And for the designer, the inability to have code backwards compatible might not make sense. IE, in AS2 there was code from AS1 that you could still use, ie the fundamental way you went about doing things remained the same. Not so when making a project for AS3.

Give it a week, AS3 will grow on you!

If you are a reasonably competent coder/hack, you will really enjoy the move to AS3. It will be painful at first, but there is so much opportunity in the latest incarnation that it will be worth it in the long run.

In the near future, hopefully you will be able to see the fruits of my toils, but in the mean time, ill try and gather snippets together into useful downloads and post them in the lab. It may take a few weeks, but I think they will still be of use :)

Redant Site Update

Just a short note (while I give my brain a break from the AS3 learning), to mention that the Redant site (where I work) has been updated.

For those interested, we moved to Radiant, a neat Ruby CMS. It was a relatively painless process – although Ben and Toby may have more of an opinion on that one. But I think the site looks gret now, and hopefully we’ll be able to live with it for while.

Download simulator

OK, so this isn’t so amazing or new or anything other than what it is… which is a very simply Flash tool I made today at work to help describe to clients how long something takes to download on a 56k dialup vs a DSL connection.

Props to OJ for the functions to calculate the speed, as I was suffering from lack of coffee, or lack of sleep, or both. Either way, let’s call this our first collaborative widget!! Hehehe!

[kml_flashembed movie="/blog/swf/download-simulator.swf" width="350" height="200" fversion="8" /]

Excel PMT function in Actionscript

Just thought id share this as it will come in useful for someone in the future. Ever wanted to use the PMT function from Excel in Flash? Well, after some digging, and after some modifications, here is it.

PMT = function(r,np,pv,fv,t) {
/*
r = the percentage rate of the loan. (decimal: 8% = 0.08)
np = number of monthly payments (integer)
pv = present value or principal of the loan (decimal)
fv = future value of the loan (after payments) (decimal)
t = paid before or after (0/1)
*/
  var vPow = Math.pow( ( 1 + r ), np );
  var vT = (t == 0) ? r : ( r /( 1 + r ) );
  return ( (vPow * pv) - fv ) / (vPow - 1) * vT;
}

Don’t say I never give you anything! (Thanks OJ for your hint on consolidating the last 2 lines into 1)