6 Replies Latest reply on Aug 19, 2011 8:56 AM by kevinklin

    Interfaceish variables in flex

    Code Girl

      I just discovered, at least in a datagrid context, that there are some Interfaceish variables that how or what they return is based upon an implemented function.  An example of one is value.  When I reference the variable value it returns the result of the value function I have defined for the field in context.  I also figured out that aparently the function must be public in scope because when I changed the value function in my program to protected, the value variable caused an error.  My question is what other variables are like this in flex?

        • 1. Re: Interfaceish variables in flex
          UbuntuPenguin Level 4

          Um, what ?  There are interfaces all over the place.  If you highlight a class type such as "Group" and click F3 you will go to that classes source file where you can see all the interfaces it implements.  You can also see the interfaces that are implemented by a class in the AS3 API files ( somewhere on the Adobe website ).  I like them the same way everyone likes them, you think about what you NEED and then you go from there.  You don't have to worry about heirarchies, subclasses and so forth you only concern yourself with the bare minimum and not the implementation so you don't end up overdesigning something.

          • 2. Re: Interfaceish variables in flex
            Code Girl Level 1

            To verify what you said, I went to the DateField and highlighted it.  I then hit F3 and it took me to DateField.as  But the variable value is not there.  So then I did the same for all the classes it implemented and not one of them had a variable value.  So then I went to all the classes that it extended and did the same and not one time did I find the variable value.   And so I suspect you miss understood my question.  Dont focus on the term Interface because I think this is something Flex has done because I have never seen this in any other java based stuff I have done before in the past.  There is something unique about the value variable and what it returns and its based upon functions you create in the context you wish value to return something.  My original question was what other types of variables like value do the same type thing.

            • 3. Re: Interfaceish variables in flex
              Code Girl Level 1

              Here, let me give you an example

               

               

               

               

              public function get value():Date

              {

               

              var date:Date = new Date(startDateField.selectedDate.toDateString() + " " + timeField.text);

               

              return date;

              }

               

               

              protected function startDateField_focusOutHandler(event:flash.events.FocusEvent):void

              {

               

               

              if (outerDocument.nonAvailDto.endDate.time < value.time)

              {

              outerDocument.nonAvailDto.endDate = value;

              outerDocument.nonAvailDto.endDate.setHours(17,00,00,00);

              }

              }

               

               

               

              I do not have a variable called value.  The only thing I have done is code a function called value.  However, when I reference the variable value, what it references is the function.  This is not how Java does things.  You can create a get and set variable function which returns the value of a private variable but you can not in java call a variable and the return is the value of a function.  So value is qutie unique in Flex.  I wonder if there are others.

              • 4. Re: Interfaceish variables in flex
                kevinklin Adobe Employee

                This is actually part of ActionScript (not Flex). When you write a getter or setter, you're actually defining a property on your class. For example:

                 

                class GetSet 
                { 
                    private var privateProperty:String; 
                     
                    public function get publicAccess():String 
                    { 
                        return privateProperty; 
                    } 
                     
                    public function set publicAccess(setValue:String):void 
                    { 
                        privateProperty = setValue; 
                    } 
                }
                

                 

                Later in my code, I can use:

                 

                var gs:GetSet = new GetSet();
                
                gs.publicAccess = "foo" // calls "set publicAccess" method
                trace(gs.publicAccess) // calls "get publicAccess" method
                

                 

                See here for more info.

                 

                -Kevin

                • 5. Re: Interfaceish variables in flex
                  Code Girl Level 1

                  Oh, IC

                   

                  So in Action Script any get or set function can be accessessed as if they were variables?  Paradon shift compared to java.

                  • 6. Re: Interfaceish variables in flex
                    kevinklin Adobe Employee

                    yes, exactly.