Working around Adobe JIRA bug ASC-2231 (Custom Constants as argument defaults)

Jan 5, 2009

Recently I came across a rather annoying bug in Flash Player 9, it effects the Flash CS3, and Flex Builder 3 (probably any that you target flash player 9 in). Its a known issue with flash player 9 and is in Adobe's JIRA with a bug number of ASC-2231.When you default a argument to a custom constant you get an error something to the effect of the one bellow. In flex builder this only appears to occur during a release build the debug builder seems to be completely happy with constants as default arguments.

Error: 1047: Parameter initializer unknown or is not a compile-time constant.

After the jump I'll explain my resolution for this annoying bug.

This is probably the most simple but most annoying bug to deal with, it takes a minimum of 3 lines to show (using good formatting). So I'm not even going to do a jump for this one. Basically all you have to do is define the argument to default to null then check if that argument is null if it is then set it to your default.

public function SomeMethod(argument:String=null):void {
    if(argument==null) {
        argument=Custom.CONSTANT_NAME;
    }
}

It's just that simple, annoying, and yes a little sloppy looking. Yes you could default it to the value of the constant but wouldn't that kind of defeat the purpose of using a constant?

According to the bug report on Adobe's JIRA this issue has been fixed in flash player 10, however at this point I have not done much work with player 10. I kind of got turned off when I realized that the 3d stuff was sucking 70-90% of my processing power (Athlon x2 64bit @2.2ghz) when the application is idle. Why I don't know but I do know that, that's really not exceptable with the potential of your clients not having a good system to run your flash application on. I was building using Flex Builder 3 targeting player 10 so I'm not sure if using Flash CS4 will fix the issue. I do know that the 3d effects example on the player 10 features site does the exact same thing on 3 different computers and one with player 10. Oh and I have an ATI Saphire 850xt 256mb so I doubt its got anything to do with that even though its a rather old card.

Anyways till next time, which hopefully won't be as long as the time between this post and the last. I'm planning one about ActionScript 3's garbage collection and fl.transitions.Tween;

Posted in: Articles |