Freelacer again! In Auckland, New Zealand!

I’ve taken the big jump and moved across several ponds to New Zealand! Not only does this mean lots of freelancing on small projects and hiding from the daily rainstorms in Internet cafés in beautiful but wet Auckland, it also means I once again have time to write my blog!

Hello Kiwis!

Liquid Interfaces in AS3

I’ve had to answer this at least three times in the last month so I’m assuming it’s a useful piece of code.

When creating liquid interfaces in ActionScript 2 you simply let your object listen to the stage for changes, like so:

1
2
3
4
5
6
7
Stage.addListener(this);
 
...
 
private function onResize() {
   this.mc_background._y = Stage.height
}

In ActionScript 3 the stage is accessible as a property in all classes inheriting from DisplayObject. Useful, but here is where the trouble begins for most people. If you try this inside your class:

1
2
3
4
5
6
7
stage.addEventListener(Event.RESIZE, drawObject);
 
…
 
private function drawObject(e:Event){
   _background.width = stage.stageWidth;
}

…it will throw an error, because the stage object is only available after your object has been added to the display list. So what do we do?

The simplest thing is to add a listener for when the object is added, and when that is done remove is and replace it with a listener for resize:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
// Add initial resizer
addEventListener(Event.ADDED_TO_STAGE, drawObject);
 
…
 
private function drawObject(e:Event){
 _background.width = stage.stageWidth;
 
 if(e.type == Event.ADDED_TO_STAGE){
    // remove initial listener
    removeEventListener(Event.ADDED_TO_STAGE, drawObject);
 
   // Add permanent listener
   stage.addEventListener(Event.RESIZE, drawObject);
 }
 
}

By doing this we get the same behavior as in AS2 but with the added benefit of a resize upon initialization.

I really should attempt to finish the animation tutorials. I’ll write some of them up during vacation, promise :)

Here’s also a video I found on the subject:

Laying plans

I guess I should apologize for the agonizingly slow pace at with I update. It’s not to do with malice, I’m just swamped with freelance work and it eats away at the little free time I have to write in. It’s a pleasant problem, though; the demand for Flash developers is higher than ever.

Next week I’ll be writing two more articles on the principles of animation, and after that I’ll try to go a little deeper and touch upon more details, such as how to draw hands. Sounds good?

Me and my blog are wearing red today. I know it’s not much help to the people of Burma, who probably would be better served by money to the democracy movement or resolutions in the UN, but maybe this helps little too. I’ll give a little and partake in a demonstration later today and I urge all of you who have the time to do the same.

I’ll see you all next week!

The lonely Flash developer

First of all, thanks to everyone who has taken the time to visit this page and write to me. There aren’t many large development teams where there is more than one Flash expert – the one I’m on is no exception – so I take any chance I can get to get to know colleagues around the world.

I know it says on the front page that this site is about development as well as animation, but I’m still working mostly in AS2 and I don’t feel there is much point in teaching this as we all have to go over to AS3 soon. But as soon as I’m settled in with it (and provided I have anything useful to say) there will be some tutorials involving development in AS3 as well.

In the mean time I’ll try to teach what little I know about animation. It’s not a whole lot. But I feel it is a part of Flash that is often forgotten now that we all work with RIAS (and let’s face it, all try to avoid being hired to do the next bloody poker site) and there is such a great need for developers. It’s a shame, for Flash is still the best option when it comes to online animation. We mustn’t forget that there is more to the graphical side of flash than site design.

Oh, and thank you all for your comments. Malay is a language I don’t speak, unfortunately, but maybe someone could help me translate what the comments and letters say?