kelvinluck.com

a stroke of luck

Actionscript 3: part 3!


Update 2:

This is a very old page imported from my previous blog. If there is missing content below or anything that doesn’t make sense then please check the page on my old blog.

Update:

These examples were created with the very first beta of actionscript 3 and run on the very first beta of the flash player 8.5. Unfortunately they don’t work on any release version of the player because of changes Macromedia/ Adobe made.

The evolution of my ActionScript 3 project has continued. Here is the current swf (remember you will need the Flash Player 8.5 to view it):


As you can see, it’s a whole heap more exciting now… It still creates the mosaic tiles from the original jpeg in the same way as the previous examples but now each tile also listens for an EventType.ENTER_FRAME event. This is basically the same as having a MovieClip.onEnterFrame event handler in older versions of Flash. Each tile is repulsed by the mouse using Barslund Repulsion (thanks to a script I grabbed from Solid Ether).

Here is the code for the example in it’s entirety:

Fairly simple really… And if anything it seems way more efficient and responsive than my attempt at bounce tweening in the last example…

Comments or suggestions for improvements appreciated :)



Second steps with ActionScript 3


Update 3:

This is a very old page imported from my previous blog. If there is missing content below or anything that doesn’t make sense then please check the page on my old blog.

Update 2:

These examples were created with the very first beta of actionscript 3 and run on the very first beta of the flash player 8.5. Unfortunately they don’t work on any release version of the player because of changes Macromedia/ Adobe made.

Update:

Check out part 3 of this series on my experiences with ActionScript 3.

I have taken my first attempt at ActionScript 3 and refined it a little… The first attempt was a very simple mosaic tool which created a mosaic from a jpeg. In this version I have improved it in a number of ways:

I now first blur each section of the image to get more of an average colour for each tile. This was a good excuse to use one of the flash.filters.* in AS and also gives a slightly better looking result. It still isn’t perfect but I spent quite a while searching the web and couldn’t find any good algorithms to find the average colour of a given bitmap (I’m sure they exist though – if you know one please leave some info in the comments).

I also decided to make the example a little bit more exciting by adding some movement to it. I initally did this by using the mx.effects classes but then I realised that these were adding 210KB to my file (unless I missed a “SimpleTween” class somewhere?). I presume that is because they depend on the whole Flex Framework but in this case (where my swf does pretty much what I want at 2KB) it seemed like some unnecessary overhead.

So I wrote a very simple little Tween class based on the new flash.util.Timer class and borrowed one of Robert Penner’s easing equations

So here is the resulting swf (note that you will need the flash player 8.5 to view it and that the movement happens when the swf loads so you may have to refresh the page to see it move):

And here is the ActionScript to make that swf:

If you compare it to my previous effort you will see that it is pretty similar… The additions are the BlurFilter and the new Tween class… They should be clear enough… The Tween class is very quickly knocked together and isn’t meant to be a proper generic replacement for the Macromedia ones but I think that such a beast may be necessary if the Macromedia ones are going to create such big files… Hopefully the next version of the zigo tween kit from Moses Supposes will include support for AS3…

Anyway – any comments on the code or suggestions for improvement appreciated :)



First actionscript 3 example


Update 3:

This is a very old page imported from my previous blog. If there is missing content below or anything that doesn’t make sense then please check the page on my old blog.

Update 2:

These examples were created with the very first beta of actionscript 3 and run on the very first beta of the flash player 8.5. Unfortunately they don’t work on any release version of the player because of changes Macromedia/ Adobe made.

Update:

Check out part 2 and part 3 of this series on my experiences with ActionScript 3.

Macromedia have just released the Flex 2 Product Line which includes the Flash Player 8.5 and ActionScript 3. It’s only an alpha but it’s a good chance to start playing around with the next generation of the Flash Platform.

Below is my first little experiment. It’s currently very simple and doesn’t do anything that you couldn’t do with Flash 8 but I think coming up with simple little projects like this and making them is a good way to learn the new syntax.

First up, here is the swf (note that you will need the flash player 8.5 to view it):

And here is the code that generated the swf:

As you can see, we load a jpeg in and then loop over it getting the colour every TILE_SIZE pixels. We then create a new Sprite which we draw a bunch of Shape’s (in this case squares) onto. The result is a mosaic like effect (I remember doing this in the early days of Flash 5 – a much more complicated process involving using PHP to analyse the image data).

Obviously a lot of room for improvement (getting the average pixel colour for a tile, having the image be dynamic rather than programmed into the AS etc etc) but not bad for the first couple of hours with a new language.

Any questions or suggestions for better ways I could have done things please use the comments :)