Consider the following code:
-
public class MyClass {
-
private var _myProperty:String;
-
-
public function MyClass() {
-
this.myProperty = myProperty;
-
}
-
-
protected function get myProperty():String {
-
return _myProperty;
-
}
-
-
private function set myProperty(value:String):void {
-
_myProperty = value;
-
}
-
}
You wouldn't expect this to result in an error, though it gives you the error "1000: Ambiguous reference to myProperty". Apparently the Flex compiler can't handle the fact that you create a getter and a setter for a property with a each a different namespace. This is filed as an issue with the Flex 2 compiler.
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.
Since I don't like to rename my getter or setter, here's another solution:
-
public class MyClass {
-
private var _myProperty:String;
-
-
public function MyClass() {
-
private::myProperty = myProperty; // !!!
-
}
-
-
protected function get myProperty():String {
-
return _myProperty;
-
}
-
-
private function set myProperty(value:String):void {
-
_myProperty = value;
-
}
-
}
Simply replace the call to this.myProperty with private::myProperty (or the access control namespace you're using) to work around this.
I don't know if this will be fixed in Flex 3. Can anybody confirm?
Add to Bloglines - Digg This! - del.icio.us - Stumble It! - Twit This! - Technorati links - Share on Facebook - Feedburner
Christophe Herreman is a software developer living in Belgium. He's working on high-end Flex and AIR solutions at 
Recent Comments