11 Replies Latest reply on Jan 13, 2010 1:51 AM by pauland

    How to restrict function calls

    RUSH-ME Level 3

      Hi Folks

       

      I have class which extends Object and It has 20 around properties. when each property is assigned some value I want to execute a single method let's say execute(). So I have called that single method in every set function of the property. like

       

      public function set propertyName(value:object):void

      {

           _propertyName = value;

           execute();

      }

       

      However when I am setting multiple properties at the same time, execute() function is called several times which is causing problem.

       

      I want to call this function only once after all the properties are being set.

       

      Any suggestions will be appreciated.

       

      Rush-me

        • 1. Re: How to restrict function calls
          iamfuric

          use

          public function set propertyName(value:object):void

          {

               _propertyName = value;

          invalidateProperties();

          }

          override protected function commitProperties():void {
              super.commitProperties();
             your_execute_method()
             }

           

          see http://livedocs.adobe.com/flex/3/html/help.html?content=ascomponents_advanced_3.html (Implementing the commitProperties() method )

          • 2. Re: How to restrict function calls
            RUSH-ME Level 3

            Hi

             

            Thanks for reply.

             

            I have mentioned that I extended an Object. So there is no commitProperties().

            Again how will I do it for multiple properties.

             

            Thanks

            Rush-me

            • 3. Re: How to restrict function calls
              pauland Level 4

              If it's always a consistent set of attributes that are updated..

               

              public function setProperties(value1:object, value2:object, value3:object):void

              {

                   _propertyName1 = value1;

                   _propertyName2 = value2;

                   _propertyName3 = value3;

                   execute();

              }

               

              alternatively remove the execute from the setters and call it explicitly after the properties have been set..

               

              obj.property1=value1;

              obj.property2=value2;

              obj.property3=value3;

              obj.execute();

               

              You could also use a groupUpdate flag to prevent individual setters from calling execute and get the flag update to call execute when it's reset.

               

              public function set groupUpdate (value:Boolean):void

              {

                   _groupUpdate= value;

                   if (value==false)

                   {

                        execute();

                   }

              }

               

              public function set property(value:Boolean):void

              {

                   _property= value;

                   if (_groupUpdate==false)

                   {

                        execute();

                   }

              }

               

              obj.groupUpdate = true;

              obj.property1=value1;

              obj.property2=value2;

              obj.property3=value3;

              obj.groupUpdate = false;

               


              Paul

              1 person found this helpful
              • 4. Re: How to restrict function calls
                RUSH-ME Level 3

                Hi Pauland

                 

                Thanks for your valuable inputs.

                 

                However my problem is I don't know how many properties I will set. It may be one property or may be all. But at the end I want to call the execute() method. As I don't know when the property/properties will be set I could not call the execute method.

                 

                Hope I am clear about my requirement.

                 

                Warm Regards

                Rush-me

                • 5. Re: How to restrict function calls
                  iamfuric Level 2

                  I think you'll be able to achieve your goal if you answer the simple question : what is "at the end" ?

                  If you know what the trigger is that causes "end"  - your ploblem is solved:

                   

                  function endTriggerHandler(){

                       obj.execute()

                  }

                  • 6. Re: How to restrict function calls
                    pauland Level 4

                    RUSH-ME wrote:

                     

                    Hi Pauland

                     

                    Thanks for your valuable inputs.

                     

                    However my problem is I don't know how many properties I will set. It may be one property or may be all. But at the end I want to call the execute() method. As I don't know when the property/properties will be set I could not call the execute method.

                     

                     

                    Hope I am clear about my requirement.

                     

                    Warm Regards

                    Rush-me

                     

                    The key is to know when you will start updating the properties and when you will finish. Then you can use my grouping solution.

                     

                    If you don't know when you have finished setting properties, then you have no hope of any solution.

                    • 7. Re: How to restrict function calls
                      RUSH-ME Level 3

                      Hi

                       

                      Thanks for your time.

                       

                      Att the end means after finishing the properties setting that may be one property or many properties. My requirement is to call the execute() once.

                       

                      Rush-me

                      • 8. Re: How to restrict function calls
                        iamfuric Level 2

                        So what is the "end" trigger/how do you know the cycle has ended?

                        User clicks "commit" button / idle-time (setProperty not called during X miliseconds) / initilizationComplete event/ other?

                        • 9. Re: How to restrict function calls
                          iamfuric Level 2

                          pauland wrote:

                           

                          If you don't know when you have finished setting properties, then you have no hope of any solution.

                          • 10. Re: How to restrict function calls
                            RUSH-ME Level 3

                            Hi

                             

                            Now I am calling execute() function from every set methods of the property.

                            which is executing several times.

                             

                            But I want a better way to handle this so that I can call it only once. Any thoughts?

                             

                            Rush-me

                            • 11. Re: How to restrict function calls
                              pauland Level 4

                              Both I and iamfuric have both pointed out that the problem is that you don't know

                              when you have finished setting the properties.

                               

                              When you can decide when property setting has finished, the solution is easy. Until you can decide when the software has finished setting properties, nobody can help you further.