[mtasc] Getters and Setters
Nicolas Cannasse
ncannasse at motion-twin.com
Wed Nov 3 01:31:58 CET 2004
The only difference is that in the second case , using explicitly addProperty failed to create a "id" field into the class type, so when accessing your "id" field you'll get a type error at compilation unless your class is 'dynamic'.
Nicolas
Right. The point is that the MTASC should allow all of these.
Or u could do this ;)
public function __set__id(id:Number):Void
{
};
public function __get__id():Number
{
};
and in the constructor add:
this.addProperty("id", __get__id, __set__id); Thats what the compiler does to getters and setters wich have the keyword (get or set).
Greetz Erik
At 16:42 2-11-2004, you wrote:
"using getters / setters is good practice"
This is true, however, you don't need to write getters and setters using the get
and set key words. You can just as easily use your own method names and produce
the same effect.
//For example you can write this:
private var _id:Number;
public function set id(id:Number) {
_id = id;
}
public function get id():Number {
return _id;
}
//like this:
private var _id:Number;
public function setID(id:Number) {
_id = id;
}
public function getID():Number {
return _id;
}
This is what I was referring to. I would recommend, as would most, that you
should never have public variables in your class and you should always use
accessor methods to manipulate all variables no matter what syntax you choose.
-Chris
-----Original Message-----
From: mtasc-bounces at lists.motion-twin.com
[mailto:mtasc-bounces at lists.motion-twin.com] On Behalf Of Brett Errington
Sent: Monday, November 01, 2004 9:40 PM
To: 'MotionTwin ActionScript2 Compiler List'
Subject: RE: [mtasc] Getters and Setters
Yeah, I'd have to agree
Using getters / setters is good practice (even though I know they have
issues in ActionScript as compared to other languages), plus I'm not going
to be able to use this compiler until they are supported as pretty much all
my AS2 code uses them and I'm not going to recode everything just to support
a different compiler.
Other than that, after giving the compiler some testing yesterday I'm really
enthusiastic about its future :) great work.
- Brett
-----Original Message-----
From: mtasc-bounces at lists.motion-twin.com
[mailto:mtasc-bounces at lists.motion-twin.com] On Behalf Of Lorenzo Sicilia
Sent: Thursday, 28 October 2004 12:19 AM
To: MotionTwin ActionScript2 Compiler List
Subject: Re: [mtasc] Getters and Setters
Allen, Christopher S. wrote:
> I'm pretty sure that there is a lot of existing code that is out there
that uses
> this style, and it would be a shame if people could not use this stuff
with your
> compiler. I would suggest that you allow this convention to keep MTASC as
> compatible as possible with the MMC.
You are rigth.
I think getter & setter is very importante because all best practice
about component use it and all my component use it :)
just my opinion.
regards Lorenzo
--
MTASC : no more coffee break while compiling
--
MTASC : no more coffee break while compiling
--
MTASC : no more coffee break while compiling
------------------------------------------------------------------------------
--
MTASC : no more coffee break while compiling
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.motion-twin.com/pipermail/mtasc/attachments/20041103/7d9c2249/attachment-0008.htm
More information about the mtasc
mailing list