blog
private setter, public getter at Jozef Chúťka's blog
October 5, 2009
ActionScript example get getter namespace private public set setter
private setter, public getter
It is possible to make private setter and public getter on actionscript classes. All you need is to use proper namespaces for getter and setter within the class.
package
{
public class GSTest extends Object
{
private var _foo:String;
public function GSTest()
{
super();
// setting value
private::foo = "bar";
// getting value
trace(public::foo);
}
public function get foo():String
{
return _foo;
}
private function set foo(value:String):void
{
_foo = value;
}
}
}usage:
var gsTest:GSTest = new GSTest();
trace(gsTest.foo); // returns "bar"compilation error:
var gsTest:GSTest = new GSTest();
gsTest.foo = "hallo";You may Leave a comment or Subscribe to Comments RSS or Trackback this entry.
Leave a comment
Please be polite and on topic. Your e-mail will never be published.