Increment and decrement operator not working when pass as an argument and variable is bindable

I learn new thing (may be a bug) in Flex that the bindable number variable cannot be pass as an argument to other function along with increment or decrement operator. If I have to pass the number then first I have to use incr/decr operator and then have to pass the number. It works fine if I remove variable as bindable. Below is the code which fails to compile
[Bindable]
private var number:Number = 0;
private function initApp():void
{
// number++; // increment here and then pass simple number will work fine.
addNumber(number++);
}
private function addNumber(num:Number):void
{
trace(num);
}

Any thoughts are welcome!

One Response to “Increment and decrement operator not working when pass as an argument and variable is bindable”

  1. Valery Silaev says:

    This is annoying but “normal” behavior.

    Try to recompile your code with “-keep” compiler argument, then check generated code — your variable is replaced with property (pair of set/get functions and new variable with mangled name).

    The real problem is how AS3 apply increment/decrement operators to property: first it call getter, then it call setter with altered value and the result of operation is a return type of setter function, i.e. “void”. Hence you get:

    1067: Implicit coercion of a value of type void to an unrelated type Number.

    Valery

Leave a Reply

You must be logged in to post a comment.