views:

95

answers:

2

The following code raises an ambiguous reference to value at compile time:

import flash.display.Sprite;

public class Main extends Sprite
{
    private var _value : Number = 0.;

    public  function get value() : Number           { return _value; }
    private function set value(v : Number) : void   { _value = v; }

    public function Main() : void
    {
        value = 42.;
    }
}

I suspect some kind of bug in the compiler, though I didn't actually read the ECMA standard.

Before someone asks those questions:

  • Private setters do make sense.
  • The ambiguity also exists with custom namespaces (which is the problem I'm facing).
A: 

I think this may be a limitation of AS3. You could create a private function called setValue() or if your set on having a setter you might be able to get away with this, although it's not very pretty.

package {
    import flash.display.Sprite;

    public class Main extends Sprite {
        private var __value :Number = 0;

        public function Main(): void {
            _value = 42;
        }
        public function get value():Number {
            return __value;
        }
        private function set _value(v:Number):void {
            __value = v;
        }
    }
}
Sandro
I agree. Thanks for comforting the idea.
Warren Seine
Another solution is to manually disambiguate with `private::value` when possible.
Warren Seine
Wow. Thanks for the tip. I didn't know you could disambiguate the variable that way.
Sandro
+1  A: 

it is indeed a bug in the compiler, and it is listed in the bugs. its stated that its an oversite of the developers and wont be fixed any time soon.

if you are needing to specifically run a function to set privately (rather than just assign the value, in which case you can leave out the setter function completely and itll run) then you will have to run a seperate function as Sandro said.

shortstick