all groups > flash actionscript > september 2007 >
You're in the

flash actionscript

group:

help in getter and setter


help in getter and setter dhina.techno
9/23/2007 5:47:52 AM
flash actionscript:
Hi,
I am a newbie in actionscript 3.0. I just created a property and the code goes
like this..

private var _lastname:String;
private var _firstname:String;

// create a "lastname" property
public function get lastname():String {
return this._lastname;
}
public function set lastname(value:String):void {
this._lastname = value;
}

// create a "lastname" property
public function get firstname():String {
return this._firstname;
}
public function set firstname(value:String):void {
this._firstname = value;
}

When i tried to build this, i got the compile time error
"The private attribute may be used only on class property definitions".
your help is highly appreciated!
Re: help in getter and setter kglad
9/23/2007 2:20:59 PM
you're allowing a public function to change (your setters) to change a private
variable. that makes no sense.

to remedy, use a different private or internal (to your class) variable name
from the public variable (made available in you setters).
AddThis Social Bookmark Button