Funny things about static const in ActionScript 3

package
{
	public class FunnyStaticConst
	{
		// mess around with the sequence but it still works
		private static const num1:int = num2;
		private static const num2:int = 100;
		// a constant object?
		private static const BASE:Object = {name:'banana', color:'yellow'};

		// constructor
		public function FunnyStaticConst()
		{
			//let's change the "constant"
			BASE.name='apple';
			BASE.color=red';
			trace(BASE.name,BASE.color);
			// the result is "apple,red"
		}
	}

}
  1. Dev

    It’s really funny !

    Object is a dynamic class, so its properties can be added at run time. May be this situation happens to any other dynamic classes as well. Let’s try it on.

  2. Eric

    Actually, I think this makes a lot of sense.

    FunnyStaticConst:BASE is a static constant, not it’s members, so of course you should be able to change them. You should not, however be allowed to redefine FunnyStaticConst:BASE altogether (such as FunnyStaticConst:BASE = {who:’me’, when:’now’}).

    BTW: Either your wp spam blocker doesn’t like Safari, or my copy of Safari is jacked up.

  3. 5566

    I thought only numbers, strings etc can be a constant. After giving some more thoughts, I realize a constant object is a constant pointer pointing to something can be changed from time to time.

  4. […] by wolsab on Tue 14-10-2008 org.as3s.Tween at AS3S.ORG Saved by saaipuntnl on Mon 13-10-2008 Funny things about static const in ActionScript 3 Saved by freckle73 on Mon 13-10-2008 ActionScriptCheatSheet.com - Adobe Flex, Adobe AIR, […]

Leave a Reply

For spam filtering purposes, please copy the number 9387 to the field below: