Ambiguous reference bug for namespaces in Flex



Before coming up with a solution for binding read-only accessors a few months ago, I had already tried out various alternatives, among which the following (which was later also pointed out by others through the comments):

Actionscript:
  1. [Bindable]
  2. // public getter:
  3. public function get someProperty ():String {
  4.   return this._someProperty;
  5. }
  6. // protected setter:
  7. protected function set someProperty (value:String):void {
  8.   this._someProperty = value;
  9. }

However, the problem here was that Flex throws an error saying "1000: Ambiguous reference to someProperty" whenever you try to use the setter.

After reading a post by Adam Flater I decided to start looking through the documentation and found out that this is in fact a known compiler bug:

174646: If a class contains accessor functions with different access control namespace attributes, (for example, aprotected setter and a public getter) using one of them causes a compile-time-error, for example,Compiler-Error 1000: Ambiguous reference to myVar
The workaround is to rename your getter or setter function to avoid the mismatch.
Common Flex 2 compiler errors and known issues

This bug doesn't seem to have been fixed in any of the Flex 2 hotfixes, and neither in the Flex 3 Beta (thanks to Wietse for testing). Let's hope the folks over at Adobe are going to do something about it..

6 Responses

Note that comments are displayed in reverse chronological order with topmost comments being freshest. Subscribe | Comment
  • Ruben says so:
    March 2nd, 2008 | Quote

    @tomwag: I don’t entirely agree with you there. First off, it’s mostly the people that call AS3 an Object Oriented language.

    But mainly I disagree because your problem (“this simple pattern of having a property read-only except for derived classes is not supported”) has little to do with a programming-language being Object Oriented or not.

  • tomwag says so:
    February 28th, 2008 | Quote

    thanks for the article

    it seems odd that AS3 calls itself an OOP language…but this simple pattern of having a property read-only except for derived classes is not supported…thanks Adobe!

  • Ruben says so:
    October 8th, 2007 | Quote

    Cool! Thanks levan :)

  • levan says so:
    October 8th, 2007 | Quote

    if setter namespace is known(for example public) you can do following to go around that bug.
    when you refference the setter do :
    myObject.public::someProperty and compiler is happy again :)

  • Ruben says so:
    August 25th, 2007 | Quote

    Ah Dano thanks so much, darn human automatism ;)

  • Dano says so:
    August 25th, 2007 | Quote

    Hi,

    May be, you want to refer to the next code:
    protected function set someProperty

    Regards,
    Dano

Leave a Reply