Bring to Front Function

This one has been covered a million times on other sites but I thought I’d include it here anyway.

To move a MovieClip or other DisplayObject to the front of the stack, you can use the following function:

public function front(asset:DisplayObject):void
    asset.parent.setChildIndex(asset,asset.parent.numChildren - 1);

// usage:

DisplayObject is used since anything that would be added to the display list (added to the stage) is a DisplayObject at its core. I’ve seen this function all over the web in different forms; quite often they only accept MovieClips or even use the * wildcard. This function will universally work with MovieClips, Textfields or any other display object you want to throw at it.

Annoying Adobe Illustrator Behavior Problem Solved

I am often given AI files (Adobe Illustrator) for the purpose of extracting assets for my flash projects. Over the past few months, I’ve been receiving a lot of files having been giving me this same issue.

Basically, any time you switch focus from Illustrator to any other application, such as flash – and then switch back to Illustrator, the program will freeze up for a good 20 to 30 seconds before allowing me to manipulate any objects. I did a few troubleshooting steps, such as starting a blank document and reproducing my steps. The problem would never reproduce with a blank file, or any files that I made. So obviously, in my mind it had to be a problem with the file.

It was time to upgrade, so I just went ahead and upgraded my adobe suite to CC (Creative Cloud). So I proceeded to open the files in Ilustrator CC and the same problem occurred.

So here is the thing – The client had told me to ignore any missing linked files in the illustrator document because they were remnants from reference material. So just for fun, I found the layers with the missing linked images, and deleted them.

Just like magic, the problem was gone. Lesson learned! Just thought I’d pass that on.

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.

Here is a simple function that will do the trick:

public function removeSpaces(input:String):String
    var split:Array = input.split(" ");
    var output:String = split.join("");
    return output;

That’s it!


trace(removeSpaces("ABCD EFG HI    JKLMNOP QRSTU      VWXYZ"));

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!

Well, times have changed and the greed of Comic-con International has shined through with a ferocious vigor. First off, there were a ton of irrelevant panels for shows such as Glee and lame vampire BS. This of course has attracted all of the annoying fans who really don’t care about comics or real science fiction.

What it also introduced was a slew of selfish fans who filled all of the ballrooms to capacity, making it so that real fans could not see their favorite panel. Keep in mind that once you are in a ballroom, comic-con staff will not make you leave. You can camp there all day, taking the seat of someone who really wants to see the panel, just so that you can be an ass.

I arrived at about 8:30am to see The Big Bang Theory panel. I got in line, which wrapped and zig-zagged across the entire length of the convention center. I got in line about 1 hour BEFORE the PANEL BEFORE the Big Bang Theory. It was some other vampire panel. I was still in the line, which had hardly moved an inch up until the vampire panel ended.

A total of “100” people left the ball room. There were over 10,000 people in line. I didn’t realize this at the time of course. So I waited and I waited. Another hour passed. Then another.

The next thing that I realized was that I had missed my panel. No one so much as gave us a warning that there was no way we were ever going to get in to see anything. You see, I was deceived by the line steadily moving ahead for about an hour. This was because people were constantly LEAVING the line. Wow.. was I pissed. Finally, my friend went to ask someone what was going on, and they said ‘Sorry man, you’re not getting in’… ‘Anyway, the panel is almost over anyway.’

It turned out that some of the people who were in line behind me never got anywhere. They missed every single panel. Don’t ask me why they were so crazy as to stay in line all day.

I was so frustrated. I felt completely duped. These people just took everyone’s money knowing damn well that there were too many people, and that only a small fraction would get into the ballrooms. I feel that the pressure needs to be put on. I Think that the celebrities should boycott the show, and start a new convention that is only for sci-fi/comic related material. Make it fun again for those of us who actually love this stuff.

The vampires and the Glee folks have their own fans. Go get your own convention. Stop ruining ours.

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.

public static function pause(timeInSeconds:int, functionToCall:Function):void {
    var timer:Timer = new Timer(timeInSeconds * 1000);
    timer.addEventListener(TimerEvent.TIMER, callFunction, false, 0, true);
    function callFunction(event:TimerEvent):void {
        timer.removeEventListener(TimerEvent.TIMER, callFunction);
        timer = null;

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

example usage (assuming that you drop this function into a class called Utilities:

private function gameWinTriggered():void{
     // player just dropped the last piece on the game board,
     // but we want to wait a second before showing the win screen

private function showWinScreen):void{
     trace('You Win!');

That’s all there is to it. Really handy for instances like these when you want to wait before a transition as to not jar the player with instant changes.