Free ActionScript

Flash AS2 & AS3 Tutorials, Game Code, Effects, Source Files & Sample Downloads

Using BitmapData – Attach Image Dynamically

Here  is a simple Flash BitmapData class example; How to attach bitmaps (images) dynamically at runtime.

Using bitmap images instead of vector shapes is a great way to increase performance in your flash games.

Preview

Download Fla Sample

Download Fla Sample

UI – Smooth Window Resize, Move and Hide

As the title says, this is a smooth window resizing, moving and hiding script. Easing animation with ActionScript.

Perfect for when you need a dynamic interface and don’t want to use the timeline to animate it.

Preview

Download Fla Sample

Download Fla Sample

Target Closest Enemy MovieClip

I’ve been thinking about how targeting the closest enemy would work and started experimenting with the algorithm. Basically AS has an array method called sortOn, that sorts objects properties in any order you want. Well, that’s the catch. It only sorts objects, not movieClips.

The work around is simple enough; when creating a new enemy object, just save a reference to the movieClip on stage inside the object’s property.

Preview

Download Fla Sample

Download Fla Sample

Update:
ActionScript 3 version of this script is available here:
http://www.freeactionscript.com/2011/07/game-enemy-manager/

Simple Flashlight Effect

Here’s a very simple Flash flashlight effect that uses almost no ActionScript. The only AS used is for rotation and key detection.

The effect is archived with a mask and a filter. The filter is a simple gradient fill, same color as the “dark”. One side the alpha is 100, the other size alpha 0. Both the mask and the filter are the same shape and size (I’m using the same movieclip actually). To make everything work, you have to rotate and move the filter and mask at the same time (along with the player).

Preview

Download Fla Sample

Download Fla Sample

Also note the center registration point for the filter, mask and player. Make sure everything is aligned or the effect will break.