[flexcoders] Re: Help on the syntax for function set blah(param:String)

2007-04-25 Thread tjcox1969
I am talking about the "set" and "get" in the function declaration.  

function set blah()

What does the set and get keyword do and why would I want to use it in
this way compared to something like function setBlah()




--- In flexcoders@yahoogroups.com, "Scott Hoff" <[EMAIL PROTECTED]> wrote:
>
> What is super special about the syntax that you pasted?
> 
> --- In flexcoders@yahoogroups.com, "tjcox1969"  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!
> >
>




[flexcoders] Re: Help on the syntax for function set blah(param:String)

2007-04-24 Thread flashcrow2000
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).

Sobottom line, getters and setters give you a way to set/get 
private properties while having some control over the actual values.


--- In flexcoders@yahoogroups.com, "Scott Hoff" <[EMAIL PROTECTED]> wrote:
>
> OK, where did you see this to raise the question? Does wherever you
> took the code from work?
> 
> --- In flexcoders@yahoogroups.com, "Scott Hoff"  wrote:
> >
> > What is super special about the syntax that you pasted?
> > 
> > --- In flexcoders@yahoogroups.com, "tjcox1969"  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!
> > >
> >
>




[flexcoders] Re: Help on the syntax for function set blah(param:String)

2007-04-24 Thread Scott Hoff
OK, where did you see this to raise the question? Does wherever you
took the code from work?

--- In flexcoders@yahoogroups.com, "Scott Hoff" <[EMAIL PROTECTED]> wrote:
>
> What is super special about the syntax that you pasted?
> 
> --- In flexcoders@yahoogroups.com, "tjcox1969"  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!
> >
>




RE: [flexcoders] Re: Help on the syntax for function set blah(param:String)

2007-04-24 Thread Robert Chyko
He is looking for the reasoning behind using implicit getters/setters.
 
Sorry, I don't have a concise answer for you, but if you Google
'implicit getter setter actionscript' I know there has been debate out
there in the past.
 
 

-Original Message-
From: flexcoders@yahoogroups.com
[mailto:[EMAIL PROTECTED] On Behalf Of Scott Hoff
Sent: Tuesday, April 24, 2007 4:48 PM
To: flexcoders@yahoogroups.com
    Subject: [flexcoders] Re: Help on the syntax for function set
blah(param:String)



What is super special about the syntax that you pasted?

--- In flexcoders@yahoogroups.com
<mailto:flexcoders%40yahoogroups.com> , "tjcox1969" <[EMAIL PROTECTED]> 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!
>



 



[flexcoders] Re: Help on the syntax for function set blah(param:String)

2007-04-24 Thread Doug Lowder
See:
http://livedocs.adobe.com/flex/201/html/basic_as_139_08.html#166714

Search for "getter" or "setter" on livedocs for more.


--- In flexcoders@yahoogroups.com, "tjcox1969" <[EMAIL PROTECTED]> 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!
>




[flexcoders] Re: Help on the syntax for function set blah(param:String)

2007-04-24 Thread Scott Hoff
What is super special about the syntax that you pasted?

--- In flexcoders@yahoogroups.com, "tjcox1969" <[EMAIL PROTECTED]> 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!
>