Add Mask to Display List when using StageScaleMode.SHOW_ALL

I spent a few hours going nuts with this one today, so save yourself some time by reading this post. Suppose that you have some content that you want to scale when the flash player is re-sized. Suppose also that you have added this line in order to accomplish it:

How to Remove Spaces from a String

Removing spaces from a string is really easy in Actionscript 3. One method is to simply convert the string to an array using the String.split() function using a space as the delimiter. Then you can use the Array.join function to put it all back together again without the spaces.

Comic-Con 2011 Can Kiss My Ass

I realize that this is completely off subject, but I am so pissed at Comic-con that I must rant.

First of all, there are just too many people, period. I went to the convention for the first time about 4 years ago, and there were a lot of people then. I had no problems getting into see my favorite panels back then. It was quite an enjoyable experience which I recommended to all of my friends!

A Simple Pause Function in Actionscript 3

Just a quick function that you can use in your library of tricks to simulate pausing in Actionscript 3.

1
2
3
4
5
6
7
8
9
10
11
public static function pause(timeInSeconds:int, functionToCall:Function):void {
    var timer:Timer = new Timer(timeInSeconds * 1000);
    timer.addEventListener(TimerEvent.TIMER, callFunction, false, 0, true);
    timer.start();
    function callFunction(event:TimerEvent):void {
        timer.stop();
        timer.removeEventListener(TimerEvent.TIMER, callFunction);
        timer = null;
        functionToCall();              
    }
}

The function takes 2 arguments:

timeInSeconds – how many seconds to wait before calling the function
functionToCall – the function to call after the given time has passed

Adjust Global Sound Volume in Actionscript 3

There is a simple way to adjust all global sound in Actionscript 3. This encompasses all playing loops, sound effects and such.

All you need is the following code:

1
2
3
4
5
import flash.media.SoundMixer;
import flash.media.SoundTransform;

// volume limits are 0 to 1 (0.1,0.2,0.3,...,1)
SoundMixer.soundTransform = new SoundTransform(0);

Of course change the number sent to the SoundTransform constructor to anything between 0 and 1 (0.5 would be half max volume, 0 is muted.)