views:

3947

answers:

2

In my ActionScript3 class, can I have a property with a getter and setter?

+11  A: 

Ok, well you can just use the basic getter/setter syntax for any property of your AS3 class. For example

package {

    public class PropEG {

        private var _prop:String;

        public function get prop():String {
            return _prop;
        }

        public function set prop(value:String):void {
            _prop = value;
        }
    }
}
Max Stewart
+2  A: 

Yes you can create getter and setter functions inside an AS3 class.

Example:


private var _foo:String = "";

public function get foo():String{
    return _foo;
}

public function set foo(value:String):void {
    _foo= value;
}

more information about getters and setters can be found here

JustFoo