Bitflag removing bug ?

Heya,

I was trying to remove a flag from a variable in JS, like so:

myNode.powerups &= ~(1 << pup.PowerupID);

but the compiler is giving me this error;

BCE0050: Operator '~' cannot be used with an expression of type 'System.Object'.

However, if I use it like this, it's completely fine:

var pid:int = pup.PowerupID;
myNode.powerups &= ~(1 << pid);

The pup.PowerupID is an int, so why is it giving me the 'Cannot be used with an expression of type Object' error ?

pup.PowerupID isn't an int, it's an Object. Casting the Object to an int allows the code to work. You haven't said how pup.PowerupID is declared, but apparently you're using dynamic typing.

Edit: after looking at the code, try changing

for (pup in powerupXMLScript.GetPowerupsByFlag(myNode.powerups))

to

for (var pup : PowerupObject in powerupXMLScript.GetPowerupsByFlag(myNode.powerups))