The set and get method are what you call setters and getters (DUH!)
and they are used when you have private members of a class and you
want to give the user the ability to change their value. Take this
example for instance:
class myObject {
private var _id:Number;
......
}
let's say you have a text box where you can change that id. if you
just say "myObjectInstance._id = textbox.text" when you click on a
button, you might get errors if you enter "dev" as an id (or any
other Not a Number value).
instead, if you define getters and setters like this:
class myObject {
private var _id:Number;
......
public function set id(value:*):void {
if (!isNaN(value)
_id = value;
else
_id = -1;
}
public function get id():Number {
if (_id == null)
_id = -1;
return _id;
}
}
then, you will have something like
"myObjectInstance.id = textbox.text" (notice here i'm using "id"
instead of "_id"; it's usually a good practice to use the same name
for setters and getters, and choose that name closely resemblant to
the property's name you want to access) and in the case of an
invalid number value, your getter will make sure the value get's set
to -1 (or whatever value you might want to use).
So....bottom line, getters and setters give you a way to set/get
private properties while having some control over the actual values.
--- In [email protected], "Scott Hoff" <[EMAIL PROTECTED]> wrote:
>
> OK, where did you see this to raise the question? Does wherever you
> took the code from work?
>
> --- In [email protected], "Scott Hoff" <shoff@> wrote:
> >
> > What is super special about the syntax that you pasted?
> >
> > --- In [email protected], "tjcox1969" <tjc1969@> wrote:
> > >
> > > I have read the section on functions in the Adobe Programming
> > > Actionscript manual, but I see no reference to this type of
syntax:
> > >
> > > [Bindable]
> > > public function set statesNames(value:ListCollectionView):void
{
> > > _statesNames = value;
> > > }
> > >
> > > public function get statesNames():ListCollectionView {
> > > return _statesNames;
> > > }
> > >
> > > Can someone point me to some documentation on this or give a
brief
> > > explanation. I am looking at a sample I found and it works,
but I
> > > want to know why and when to use this type of "function set
blah()"
> > > syntax over "function setBlah()"
> > >
> > > Thanks!
> > >
> >
>