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"
}
}
}
This entry was posted
on Friday, August 22nd, 2008 at 3:47 am and is filed under Others.
You can follow any responses to this entry through the RSS 2.0 feed.
You can leave a response, or trackback from your own site.
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.
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.
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.
[…] 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, […]