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):
-
[Bindable]
-
// public getter:
-
public function get someProperty ():String {
-
return this._someProperty;
-
}
-
// protected setter:
-
protected function set someProperty (value:String):void {
-
this._someProperty = value;
-
}
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..
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.
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!
October 8th, 2007 | Quote
Cool! Thanks levan
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
August 25th, 2007 | Quote
Ah Dano thanks so much, darn human automatism
August 25th, 2007 | Quote
Hi,
May be, you want to refer to the next code:
protected function set someProperty
Regards,
Dano