Category Archives: Actionscript

Dynamic Mask Symbol

If you’ve done any significant amount of animation in Flash then you’ve probably run into this problem. You want to give a symbol partial alpha, but that ends up giving you a big mess where each individual sub-symbol is alpha’d down, rather than just the symbol you’re actually working with. Blech!


No Es Bueno

I ran into this problem once again yesterday while working on my demo reel and I decided I’d had enough.  I pulled out a trick I learned from Mike Bambino while I was working at Trilogy Studios.  It turns out that if you do it dynamically (using Actionscript) then you can make a mask that supports semi-transparency.  It lets you do awesome neato stuff like smooth gradient masks:



Awesome and Neato

What I wanted to do this time is to fade single characters in and out without affecting the other characters around them.  Normally I’d do something with solid overlays to give the impression of a clean dissolve, but it wasn’t working this time.  The characters were overlapping a bit, so the overlay would end up affecting both of them in an undesirable way.

To solve the problem I simply made a solid rectangular symbol with the relevant Actionscript in it.  At run-time it gloms itself onto whatever movie clip is directly below it on the display list and says “hey you!  I’m gonna be your mask now!”  Then I simply fade the mask symbol on the timeline however I please in order to fade its maskee in and out.

Easy, huh?

Here’s the source code in case you’d like to apply it to your own stuff.  Just put this on the first frame of your mask movie clip, then put the mask symbol directly above the thing you want to mask:

var maskee:DisplayObject;

// Call the enter_frame function for the first frame

function enter_frame(evt:Event)
	//trace("enter frame");

	var my_index:int = parent.getChildIndex(this);
	// Find the symbols just below this one
	maskee = parent.getChildAt(my_index - 1);
	// If there's something there, mask it.
		// Cache as Bitmap must be turned on for both the mask and the maskee
		cacheAsBitmap = true;
		maskee.cacheAsBitmap = true;
		//trace("masking " +;
		maskee.mask = this;

// Remove the reference to the mask if it gets removed from the stage
function removed_from_stage(evt:Event)
	maskee.mask = null;
	removeEventListener(Event.ENTER_FRAME, enter_frame)
	//trace("removed mask");

addEventListener(Event.REMOVED_FROM_STAGE, removed_from_stage);
addEventListener(Event.ENTER_FRAME, enter_frame)

And here’s a Flash file with it all set up and working, just to make it totally easy to see how it works:

Dynamic mask.fla (57KB)

Apple is wandering in the direction of Lawful Evil

Some of you may have heard about the kerfuffle in the last few days between Apple and Adobe. Briefly, Apple made a change to their developer agreement that makes it against the rules to use any language other than C, C++, Objective C, or Javascript when making applications for the iPhone/iPod/iPad. Furthermore, they’ve disallowed abstraction or compatibility libraries. The practical upshot of this is that Adobe’s most-touted feature in its new version of Flash, the ability to compile directly to an iPhone, is now pretty much worthless. Have no doubt, this was a change directed firmly at Adobe, and it encroaches into the region of Evil and perhaps Monopolistic. This post at the Flash Blog pretty much sums up my feelings.