Tony Polinelli
Tarwin Stroh-Spijer

contact [at]

6/25 Easey Street
Collingwood, 3066
Vic, Australia

+61 3 8060 5321

Archive for the ‘Flash’ Category

Monday, May 5th, 2008

Sometimes you want to be able to use a timeout or interval but, as they are tied to milliseconds, if the frame-rate of your movie goes down from what you expected – games is a good example – then you can run into trouble.

I recently had this problem with a game, that when the frame rate lowered, cyclic “emitters” (ie creating bubbles underwater) would not be synced with the expeted speed of the game.

The solution. A setInterval and setTimeout that you can set using milliseconds (or frames if you want) and will be called at the expected number of frames. The only caviet with this approach is that it needs to be inited with the stage object, both so it can get an ENTER_FRAME event and the current FPS.

Friday, April 25th, 2008

To my surprise i found the other day that, with the new AVM2, you can now access the content that you have drawn to the stage. It makes perfect sense, but i just assumed that it was locked. As a test, if you can draw something on the stage and then add the code

  1. getChildAt(0).x = 100

This is reallly handy if you want to remove all the content from a clip, maybe move it into another, or add it dynamically to a child, then add effects. One note your drawing items are merged together (it doesnt preserve layers) unless there is a MovieClip between the layers. This is the only time that it splits layers into separate clips.

Friday, April 25th, 2008

So you might think that rounded corners is easy in as3 with the new drawing tools. This is only so true if you don't want it dotted.

Thanks to senocular AS2 which was easily converted to an as3 version for as3 we can draw dotted lines and curves with actionscript. This left me with the task of using the quadratic drawing tools (no i didnt add a cubic curveTo to the Dashed line class) to draw circles (or quarters of circles, for the curners), which isnt the easiest, but i'll spare you the details and simply say, its done!

Using Draw.curvedBox(obj, offsetX, offsetY, width, height, cornerRadius) we can draw into any graphics object (whether it be a normal or a DashedLine Object). This is essential as the Dashed line tool doesnt actually give us a fill, so we might need to draw a normal shape for the background.

  1. import com.senocular.drawing.DashedLine
  2. import com.tonp.utils.Draw
  3. var dl = new DashedLine(this,1,5);
  4. dl.lineStyle(3,0x000000,1);
  5. Draw.curvedBox(dl,10,10,100,100,20)

to draw a curved corner box with a fill, or solid outline, send in as the first attribute (or just the mc in as2)

So we can now do a box with curved corners in either AS2 or AS3 and in dotted or normal... phew!

Friday, April 25th, 2008

Rendering a vector for every frame of a repeated animation (like in most games) take a lot of CPU. It takes even more CPU to have lots of complex characters on screen - many the same sprite.

cacheAsBitmap in flash is good, but only if you have static objects but recreates the bitmap data of an animation every frame, making it run even slower. The best solution is to cache each frame of an animation as a bitmapData, and then switch between them each frame. This works well until you have multiple instances of the same sprite - You dont want to pre-render the bitmap data and keeping it in memory many times, so it is best to keep a library of animations, and then reference the cached frames for each instance.

Another advantage of this technique is it seems to make use of Flash's new multi-core support. On a dual core CPU it can, if you push it, take almost 100% of resources. Trying it on a quad-core seemed only to take up two CPUs though. I guess this is both a blessing and a curse as you're more likely to grind a users system to a halt, even if they have multiple CPUs.

Animations copyright Nathan J. -

Monday, April 14th, 2008

I've always wanted to use a Joytick with my Flash games.

A while ago I was working on small game for Lorial - in-store advertising for Biotherm - through a great company Eness. It was a simple "catch the falling objects with a timelimit game" made in Flash, but needeed to be controlled using a joytick as it had to be simple and easy to use for anyone walking through Myer.

After a little research I found the amazing program AutoHotKey. This lets you specify macros to do things like using a joystick as a mouse or keys, or pressing a combination of keys and starting a program. Using this amazing peice of software (Windows only sorry) and hacking around with some of their joystick input exampels it was easy to map joystick movements and buttons to the arrow keys and "A" on the keyboard, which were then read by Flash.

On a recent game I've been working on (Scarygirl) I've found that user testing on the keyboard really gets in the way of the gameplay itself, especially for those not used to games. It was a lot easier to hand them a Playstation 2 DualShock controlller attached via a USB converter and have an AutoHotKey script running that converted the D-Pad and buttons to input. The hardest part of this is finding which button on the controller relates to what input into windows. The easiest way I found to work with this was Start->Control Panel->Controllers and just writing down a list of buttons as I pressed them.

So yeah. Easy. And fun. Some games are just so much better with a good controller - just never let me catch you playing an FPS on a console!

Monday, April 14th, 2008

I've been playing with JSFL a little recently. It was really hard to begin finding any resources on how to use it and those I did find were pretty sparse with information. So to help the community out I'm going to start posting my experiments, some useful, some only good for me, for everyone to take a look at, take apart and generally learn from.

The first one is one of the simplest. It lets you select all Elements of the same class on the stage. Simply select one of them, say a RadioButton, then choose the TMP - Select Same Class from the Commands menu and all other RadioButton instances should be selected.

Our Friends:

Powered by haXe / poko cms | Copyright 2008-09 TouchMyPixel