Archive for the 'Flash/Flex/Flex Builder' Category

AprilScript: ActionScript worst practices

In honor of the date, and in the spirit of the old Obfuscated C Code Contest, I've written a bit of code to demonstrate some of the more, shall we say, interesting things you can do with ActionScript.

The code:

package {
    import flash.display.* 
    import flash.text.*

    public class AprilFools extends Sprite {
        エイプリルフール var Number = 4..toString()

        use namespace エイプリルフール

        function AprilFools()
        {
            get = set
            set = get

            with (createTextField())
                text = new Date(Number).toDateString()
        }

        function get get() { return Number + <>< {Number}
            b={"/"+Number.split(/\//)[0]*502.25}/></>..@b }
        function set get(set) { Number = set+'/'+set/4 }

        function get set() { return Number }
        function set set(get) { Number = get }

        // nothing fun here
        function createTextField():TextField
        {
            stage.scaleMode = StageScaleMode.NO_SCALE;
            stage.align = StageAlign.TOP_LEFT;
            var textField:TextField = new TextField();
            textField.width = 1000;
            addChild(textField);
            return textField;
        }
    }
}

namespace エイプリルフール

The program's weak spot is creativity in terms of what it actually does -- just some static text output. Pretty pathetic really. All my effort went into the ActionScript. Click here to see the result. It's probably not worth the effort to try to figure out what it does before running it; that's not really the fun part. The fun part is trying to figure out why the heck the thing compiles at all; what the individual lines of code actually mean; and what sick features of the language I am taking advantage of. Tell me what you find.

All Flex developers, please do this.

Even if you aren't a Mac user, please do this to your Flex apps.

Even if you aren't the kind of person who uses the scroll wheel on your mouse or two-finger scroll on your trackpad, please do it.

If you do, you will make some of your users very very happy.

How to capture the compilation options used by Flex Builder

Suppose you are trying to set up a nightly build system -- your developers use Flex Builder during the day, and you are creating an Ant task that runs every night. And you want the Ant task to use exactly the same build settings that are used by the developers.

mxmlc and compc have a -dump-config option to dump all settings to a file. Later, the settings in that file can be read back in with -load-config.

So, do this:

  • In Flex Builder, do Project Properties
  • Click the "Flex Compiler" tab
  • In the "Additional compiler arguments" box, add "-dump-config full-path-to-output-file". For example, on Windows, "-dump-config C:\myconfig.xml"; on Mac, "-dump-config /Users/myname/myconfig.xml". (If you use a relative path, the file will be put in some odd hard-to-find place.)
  • Click OK.  If Build Automatically is on, just clicking OK will cause the file to be built; if it is off, do a build now.
  • Now that the settings have been dumped, go back to your project settings and remove the -dump-config option.
  • Tweak the settings file as necessary (one thing you will almost certainly want to do is change <debug>true</debug> to <debug>false</debug> if your nightly build is supposed to do a release build), and use it in your nightly build script.

Please be aware that this only captures compiler settings; it doesn't capture all the other little things that Flex Builder does for you, like compiling Flex library projects that your project depends on, copying non-embedded assets to the output directory, optimizing modules for the application, extracting RSLs, copying the HTML template, and so on.

More info here. Please read that, it has additional info you will probably need.

« Previous PageNext Page »