Tag Archives: Flash

Instance Arrays in Flash

One thing that I thought wasn’t planned very well in Flash 9 and AS3 is having a bunch of instances on your stage, and then having to declare each one in your ActionScript files. Up until now, I have been naming all my objects something like “obj0”, “obj1”, “obj2”, etc and then in my constructor, adding each of those objects manually to an array one at a time. The problem with this, obviously, as it doesn’t cater well to expansion or large numbers of objects. If I added more objects to the stage, I’d have to update the code.

Here’s code I came up with today:

public class RollingNumberDisplay extends MovieClip {

    protected var digits:Array;

    /**
      * Constructor
     */
    public function RollingNumberDisplay() {
        super();
        var counter:uint;

        digits = new Array();

        counter = 0;
        while(this.hasOwnProperty("digit" + counter)) {
            digits.push(this["digit" + counter]);
            counter++;
        }

        trace("length=" + digits.length);
    }

}

Unblocking backgrounds in Flash

A long while ago I wrote an article describing how to block background elements in Flash. The problem I used to encounter was that my background elements were clickable through other movie clips on the stage.

Recently, I’ve had the opportunity to use Flash CS3 and ActionScript 3.0 and my problems with click handling have been flipped upside-down. The annoyance I encounter now, is that I cannot click through movie clips, even if their alpha is set to be completely transparent. For example, if I have a series of clickable movie clips positioned under another clip acting as a glare.

Read More →

Flash addXMLPath example

I was recently working on an application in Flash which required the use of Flash’s Locale class. It didn’t take long before I was consulting the documentation for some of the methods and I ran across the addXMLPath method. Adobe (Macromedia at the time) was nice enough to include an example of how to use Locale.addXMLPath, however the example provided doesn’t even use addXMLPath()! The example provides no extra help whatsoever. I’ve created this small article to give an example on how to use Locale.addXMLPath().

Read More →

Blocking Backgrounds in Flash

Note: This article was written in 2006 and applies to Flash ActionScript 2.

A very common problem in Flash (AS2) is as follows:

Your stage is covered in buttons and interactive movie clips and you want to put something on top of your entire stage and disable all the elements in the background all at once.

For example, you might be making an app with lots of text input fields and buttons. Let’s say you wanted to pop up a warning message on top of the screen to warn the user about something. Doing so, you want all the buttons in the background to be disabled.

Here’s a simple method to accomplish that task…

  1. Make a completely transparent rectangle the same size as your stage on the layer above everything that you want to block.
  2. Convert this rectangle to a Movie Clip.
  3. Give this Movie Clip instance a name of “blocker”.
  4. In the frame that the movie clip appears, write the following ActionScript:

Actionscript:

this["blocker"].onRelease = function() { };
this["blocker"].enabled = false;

Doing this creates a movie clip which has an “onRelease” action assigned to it. Even though we’ve assigned no code to the onRelease function, Flash still sets up the Movie Clip to be clickable. The second line of code disables the clip so that it isn’t clickable. By doing so, you successfully block everything beneath the clip. Voila!

Flash Components Missing Fonts

So here’s a nice bug that took me about a month to figure out:

  1. Make a component (SWC file) in Flash 8 that uses a Dynamic text field. Set the font to Arial and make sure that you embed the characters that you need. I embedded [a-zA-Z0-9].
  2. Export your SWC file.
  3. Drag your component from the Components panel into a new flash file.
  4. If your flash file does not use any text fields that contain the font Arial, then you’ll be good to go. However, try putting a static text field on your stage with the word “HELLO”. If your Flash acts the same way that mine does, it will drop all of the embedded characters from your component except for the characters that appear on the stage (i.e. H, E, L and O).
  5. The only solutions that I have found are:
    1. Make a separate dynamic text field off the stage which embeds all of the characters that your Component does. This solution is not recommended though, because if your component ever changes its font, you may run into the same problem all over again.
    2. Never use static text on the same stage that you are putting a component. This seems a bit drastic, but if you make a point of only using dynamic text fields with reasonable font sets embedded, then you will run into this problem less.

I emailed Adobe about this problem, but they wouldn’t support me because they don’t deal with custom components. Hopefully it’s addressed and fixed in future versions.

New site launched

Last week I launched a new site. KingKarma.com features a few nifty features:

  • The band wanted music to be playing throughout the entire site. The timeline was a bit short to try anything with Ajax, so I went with an iframe.
  • The top section and nav is made in flash so that the buttons can animate and I’ve included a music player which loads external MP3’s and a newsletter sign-up which taps into my mailing list script written in PHP.
  • The lyrics page is a bit fancy. The band wanted the song names on the left to remain static while the rest of the page scrolled down. CSS2’s position:fixed wouldn’t have done this nicely, but unfortunately for me, not all browsers support position:fixed. So I figured having the song names follow the scrolling in the frame was the best option. Thanks to Robert Hahn for helping me with making this work.
  • The last cool thing about the site is the news box on the front page. This is made in flash, but it loads the text from MySQL which the band can administer and change whenever they have things to say.

A pretty full site for a short timeline. I’m happy with the way it turned out.