PDA

View Full Version : Problems with getter/setter functions


burtonrider1983
08-27-2006, 10:38 PM
I have a private variable within my class and I have public getter and setter functions to add this variable as a property of the instances of the class.
I have followed every piece of documentation I have found on the issue, but I keep getting multiple errors.
This is really getting a bit frusterating. I am sure it is something simplistic that I am overlooking, but I just can't see it.

I declare the variable inside of the class...
private var regClicked:Boolean;

I have the getter/setter functions....
public function set regClicked(newMode:boolean=true):void{
regClicked = newMode;
}

public function get regClicked():boolean{
return regClicked;
}

I get these errors....
C:\Documents and Settings\Amanda\My Documents\Ian\flash\flex2\applications\UIButton.as (140): col: 29 Error: Incompatible override.

public function set regClicked(newMode:boolean=true):void{
^

C:\Documents and Settings\Amanda\My Documents\Ian\flash\flex\applications\UIButton.as( 140): col: 29 Error: Duplicate function definition.

public function set regClicked(newMode:boolean=true):void{
^

C:\Documents and Settings\Amanda\My Documents\Ian\flash\flex\applications\UIButton.as( 144): col: 29 Error: Incompatible override.

public function get regClicked():boolean{
^

C:\Documents and Settings\Amanda\My Documents\Ian\flash\flex2\applications\UIButton.as (144): col: 29 Error: Duplicate function definition.

public function get regClicked():boolean{
^

C:\Documents and Settings\Amanda\My Documents\Ian\flash\flex\applications\UIButton.as( 33): col: 13 Error: Ambiguous reference to regClicked.

regClicked = true;
^

C:\Documents and Settings\Amanda\My Documents\Ian\flash\flex\applications\UIButton.as( 100): col: 16 Error: Ambiguous reference to regClicked.

if(regClicked){
^

C:\Documents and Settings\Amanda\My Documents\Ian\flash\flex\applications\UIButton.as( 141): col: 13 Error: Ambiguous reference to regClicked.

regClicked = newMode;
^

C:\Documents and Settings\Amanda\My Documents\Ian\flash\flex\applications\UIButton.as( 145): col: 20 Error: Ambiguous reference to regClicked.

return regClicked;
^

astgtciv
08-28-2006, 01:08 AM
The get/set function names and the private var name have to be different. Change the private var to (e.g.) _regClicked (and refer to it as such in the methods).