1 Reply Latest reply on Sep 25, 2007 3:53 PM by Senor_Roberto

    Custom Classes, Encapsulation and Flex's display components

      Hi all,
      I'm quite new to OOP and would appreciate some help if anyone can spare me the time?

      I've written some ActionScript classes in Flex Builder 2 and to the best of my early knowledge, am (hopefully on the right track by...?) trying to keep my classes like a black box and only allowing access to their properties through their own API of methods.

      I have explicit getters for properties I would like to display in Flex display components whose dataProvider is an ArrayCollection of these classes for example.

      The problem is that eg: a DataProvider obviously isn't going to recognise my explicit getters as being properties I want to display.

      I don't know what to do here, I'd have though I shouldn't be making these properties public, and I don't really want to use implicit getters either.

      I'd appreciate any advice you might have, thanks a lot.

        • 1. Re: Custom Classes, Encapsulation and Flex's display components
          Senor_Roberto Level 1
          It sounds like you're using Java style getters and setters i.e. getX, setX etc.

          In AS3, there is a function/property construct, see below:

          public class TestProperties {

          private var memberVariable:String;

          public function set publicPropertyName (value:String) : void {
          this.memberVariable = value;

          public function get publicPropertyName () : String {
          return this.memberVariable;


          This sets up virtual properties. This is the ActionScript way of doing getX and setX and it's very similar to C# properties. Once you have the class above, you can do this:

          var test:TestProperties = new TestProperties();

          test.publicPropertyName = "Foo";



          So it acts exactly like a public property would - including data bindings to DataGrids and other controls, but maintains OO encapsulation.